feat: add scoped history and artifacts
This commit is contained in:
@@ -37,6 +37,8 @@ export const answerUiSpecSchema = z.object({ root: key, elements: z.record(z.obj
|
||||
});
|
||||
|
||||
export const answerUiInputSchema = z.object({ block_id: key, fallback_text: z.string().min(1).max(4000), spec: answerUiSpecSchema }).strict();
|
||||
export const answerUiBlockSchema = answerUiInputSchema.extend({ version: z.literal("answer-ui@1") })
|
||||
.refine((block) => JSON.stringify(block).length <= 100000, "界面块过大");
|
||||
export const parseAnswerUiInput = (value: unknown) => {
|
||||
const parsed = answerUiInputSchema.safeParse(value);
|
||||
return parsed.success ? { version: "answer-ui@1" as const, ...parsed.data } : null;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
export type InputDelivery = "steer" | "queue";
|
||||
export type ResponseInput = { id: string; text: string; delivery: InputDelivery; status: "pending" | "delivered" };
|
||||
export type ResponseInput = { id: string; text: string; delivery: InputDelivery; status: "pending" | "delivered" | "cancelled" };
|
||||
type InboxRuntime = {
|
||||
enqueueUserInput: (sessionId: string, input: ResponseInput) => Promise<void>;
|
||||
listPendingUserInputs: (sessionId: string) => Promise<ResponseInput[]>;
|
||||
@@ -19,7 +19,7 @@ export class ResponseInputTracker {
|
||||
|
||||
markReady() { this.releaseReady(); }
|
||||
close() { this.accepting = false; this.releaseReady(); }
|
||||
get hasAdditionalInput() { return this.items.size > 0; }
|
||||
get hasAdditionalInput() { return [...this.items.values()].some((input) => input.status !== "cancelled"); }
|
||||
|
||||
async restore() {
|
||||
for (const input of await this.runtime.listPendingUserInputs(this.sessionId)) this.items.set(input.id, input);
|
||||
@@ -53,8 +53,9 @@ export class ResponseInputTracker {
|
||||
|
||||
observe(type: string, data: { inboxID?: string; delivery?: InputDelivery }) {
|
||||
const input = data.inboxID ? this.items.get(data.inboxID) : undefined;
|
||||
if (!input) return;
|
||||
if (!input || input.status !== "pending") return;
|
||||
if (type === "session.inbox.delivered") input.status = "delivered";
|
||||
else if (type === "session.inbox.cancelled") input.status = "cancelled";
|
||||
else if (type === "session.inbox.delivery.changed" && data.delivery) input.delivery = data.delivery;
|
||||
else return;
|
||||
this.changed({ ...input });
|
||||
|
||||
@@ -18,6 +18,8 @@ export const responseRequestSchema = z.object({
|
||||
conversation: z.union([z.string().min(1).max(128), z.object({ id: z.string().min(1).max(128) }).strict()]).optional(),
|
||||
metadata: z.record(z.string().max(64), z.string().max(512)).refine((value) => Object.keys(value).length <= 16).optional(),
|
||||
tjwater: z.object({
|
||||
topic_id: z.string().uuid().optional(),
|
||||
client_message_id: z.string().min(1).max(128).optional(),
|
||||
delivery: z.enum(["steer", "queue"]).optional(),
|
||||
input_id: z.string().regex(/^msg_[a-f0-9]{32}$/).optional(),
|
||||
approval_mode: z.enum(["request", "always"]).default("request"),
|
||||
|
||||
Reference in New Issue
Block a user