@hosty-sdk/app 0.49.0 → 0.51.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agent-client.d.ts +28 -1
- package/dist/agent-client.js +104 -5
- package/dist/agent-schemas.js +31 -4
- package/dist/agent-server.js +11 -5
- package/dist/agent.d.ts +18 -0
- package/dist/agent.js +1 -0
- package/package.json +1 -1
- package/schemas/agent-event-v1.schema.json +352 -34
- package/schemas/agent-v1.openapi.json +862 -64
package/dist/agent-client.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type AgentAttachment, type AgentAttachmentChunk, type AgentAttachmentChunkReceipt, type AgentAuthorizer, type AgentAuthorizationRequest, type AgentCancelInput, type AgentCapabilities, type AgentConfigurationCreate, type AgentConnectionPage, type AgentConnectionUsage, type AgentControlReceipt, type AgentEvent, type AgentHistoryObservation, type AgentModelCatalog, type AgentOperation, type AgentPreparedRequest, type AgentProviderRef, type AgentResponseInput, type AgentRunControlInput, type AgentRunInput, type AgentRunSnapshot, type AgentSession, type AgentSessionCreate, type AgentSessionPage, type AgentWatchItem } from "./agent.js";
|
|
1
|
+
import { type AgentAttachment, type AgentAttachmentChunk, type AgentAttachmentChunkReceipt, type AgentAuthorizer, type AgentAuthorizationRequest, type AgentCancelInput, type AgentCapabilities, type AgentConfigurationCreate, type AgentConnectionPage, type AgentConnectionUsage, type AgentControlReceipt, type AgentEvent, type AgentHistoryObservation, type AgentHistorySessionState, type AgentModelCatalog, type AgentOperation, type AgentPreparedRequest, type AgentProviderRef, type AgentResponseInput, type AgentRunControlInput, type AgentRunInput, type AgentRunSnapshot, type AgentSession, type AgentSessionCreate, type AgentSessionPage, type AgentWatchItem } from "./agent.js";
|
|
2
2
|
export type AgentClientOptions = {
|
|
3
3
|
provider: AgentProviderRef;
|
|
4
4
|
authorize: AgentAuthorizer;
|
|
@@ -87,8 +87,34 @@ export type AgentHistoryPage = {
|
|
|
87
87
|
through: string;
|
|
88
88
|
nextCursor: string | null;
|
|
89
89
|
};
|
|
90
|
+
type HistoryPageOptions = {
|
|
91
|
+
through?: string;
|
|
92
|
+
limit?: number;
|
|
93
|
+
};
|
|
90
94
|
/** Open one read-only installation subscription. Resume from the last durably applied position. */
|
|
91
95
|
export declare function watchAgentHistory(options: AgentHistoryOptions): AsyncGenerator<AgentHistoryObservation>;
|
|
96
|
+
/** Subscribe at the provider's current boundary. Supply a previous cursor to validate archive ancestry. */
|
|
97
|
+
export declare function watchLiveAgentHistory(options: AgentHistoryOptions & {
|
|
98
|
+
onReady: (boundary: string) => void | Promise<void>;
|
|
99
|
+
}): AsyncGenerator<AgentHistoryObservation>;
|
|
100
|
+
export declare function readAgentHistoryStates(options: AgentHistoryOptions & HistoryPageOptions & {
|
|
101
|
+
afterSession?: string;
|
|
102
|
+
}): Promise<{
|
|
103
|
+
through: string;
|
|
104
|
+
sessions: AgentHistorySessionState[];
|
|
105
|
+
nextSession: string | null;
|
|
106
|
+
}>;
|
|
107
|
+
export declare function readAgentHistoryRange(options: AgentHistoryOptions & {
|
|
108
|
+
through: string;
|
|
109
|
+
sessionId: string;
|
|
110
|
+
epoch: string;
|
|
111
|
+
from: number;
|
|
112
|
+
to: number;
|
|
113
|
+
limit?: number;
|
|
114
|
+
}): Promise<{
|
|
115
|
+
observations: AgentHistoryObservation[];
|
|
116
|
+
nextPosition: number | null;
|
|
117
|
+
}>;
|
|
92
118
|
/** Read a bounded page at a stable installation feed position. Pass through to subsequent pages. */
|
|
93
119
|
export declare function readAgentHistoryPage(options: AgentHistoryOptions & {
|
|
94
120
|
through?: string;
|
|
@@ -100,3 +126,4 @@ export declare function parseAgentSse(response: Pick<Response, "body">, maxBytes
|
|
|
100
126
|
event: string;
|
|
101
127
|
data: string;
|
|
102
128
|
}>;
|
|
129
|
+
export {};
|
package/dist/agent-client.js
CHANGED
|
@@ -280,10 +280,18 @@ export class AgentClient {
|
|
|
280
280
|
options.signal?.throwIfAborted();
|
|
281
281
|
}
|
|
282
282
|
}
|
|
283
|
-
async function historyResponse(options, accept, page) {
|
|
283
|
+
async function historyResponse(options, accept, page, endpoint, parameters) {
|
|
284
284
|
const url = new URL(options.url);
|
|
285
285
|
if (!["https:", "http:"].includes(url.protocol) || url.username || url.password || url.search || url.hash || !options.token)
|
|
286
286
|
throw new AgentApiError("authorization_invalid", "Invalid installation history binding.", 401);
|
|
287
|
+
if (endpoint) {
|
|
288
|
+
if (!url.pathname.endsWith("/history/events"))
|
|
289
|
+
throw new AgentApiError("authorization_invalid", "Expected an installation history events URL.", 401);
|
|
290
|
+
url.pathname = url.pathname.slice(0, -"events".length) + endpoint;
|
|
291
|
+
for (const [key, value] of Object.entries(parameters ?? {}))
|
|
292
|
+
if (value !== undefined)
|
|
293
|
+
url.searchParams.set(key, String(value));
|
|
294
|
+
}
|
|
287
295
|
const after = agentReplayCursor(options.cursor);
|
|
288
296
|
if (after)
|
|
289
297
|
url.searchParams.set("after", after);
|
|
@@ -305,7 +313,9 @@ async function historyResponse(options, accept, page) {
|
|
|
305
313
|
detail = JSON.parse(raw)?.error;
|
|
306
314
|
}
|
|
307
315
|
catch { /* Older providers may return a plain 404. */ }
|
|
308
|
-
|
|
316
|
+
if (endpoint === "live" && (response.status === 404 || response.status === 422 && ["unsupported_operation", "unsupported_capability"].includes(detail?.code ?? "")))
|
|
317
|
+
throw new AgentApiError("history_live_unsupported", "The provider does not support live history recovery.", 404);
|
|
318
|
+
throw new AgentApiError(detail?.code ?? "provider_failed", detail?.message ?? `History request failed (${response.status}).`, response.status, detail?.retryable === true);
|
|
309
319
|
}
|
|
310
320
|
if (response.headers.get("content-type")?.split(";")[0]?.trim().toLowerCase() !== accept) {
|
|
311
321
|
await response.body?.cancel();
|
|
@@ -316,12 +326,13 @@ async function historyResponse(options, accept, page) {
|
|
|
316
326
|
function historyObject(value) {
|
|
317
327
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
318
328
|
}
|
|
329
|
+
const historyIdentity = (id) => typeof id === "string" && id.length > 0 && id.length <= 512;
|
|
330
|
+
const historyPosition = (n) => typeof n === "number" && Number.isSafeInteger(n) && n > 0;
|
|
319
331
|
function historyObservation(value, cursor, provider) {
|
|
320
332
|
if (!historyObject(value) || typeof cursor !== "string" || !agentReplayCursor(cursor))
|
|
321
333
|
throw new AgentApiError("event_invalid", "The history observation is missing its cursor.", 502);
|
|
322
334
|
const { sessionId, runId, generation, userId, principalId } = value;
|
|
323
|
-
|
|
324
|
-
if (!identity(sessionId) || !identity(runId) || !identity(generation) || !identity(userId) || !identity(principalId) || !historyObject(value.item))
|
|
335
|
+
if (!historyIdentity(sessionId) || !historyIdentity(runId) || !historyIdentity(generation) || !historyIdentity(userId) || !historyIdentity(principalId) || !historyObject(value.item))
|
|
325
336
|
throw new AgentApiError("event_invalid", "The history observation is missing its identity.", 502);
|
|
326
337
|
const raw = value.item;
|
|
327
338
|
let item;
|
|
@@ -344,7 +355,12 @@ function historyObservation(value, cursor, provider) {
|
|
|
344
355
|
if (snapshot && (snapshot.ref.id !== runId || snapshot.sessionId !== sessionId || snapshot.generation !== generation
|
|
345
356
|
|| provider && !sameProvider(provider, snapshot.ref.provider)))
|
|
346
357
|
throw new AgentApiError("event_invalid", "History snapshot identity changed.", 502);
|
|
347
|
-
|
|
358
|
+
const { epoch, sessionPosition } = value;
|
|
359
|
+
if (value.sourceHistoryIncomplete !== undefined && value.sourceHistoryIncomplete !== true || epoch !== undefined && !historyIdentity(epoch) || sessionPosition !== undefined && (!epoch || !historyPosition(sessionPosition)))
|
|
360
|
+
throw new AgentApiError("event_invalid", "Invalid session history position.", 502);
|
|
361
|
+
return { sessionId, runId, generation, userId, principalId, item, cursor,
|
|
362
|
+
...(epoch !== undefined ? { epoch } : {}), ...(sessionPosition !== undefined ? { sessionPosition } : {}),
|
|
363
|
+
...(value.sourceHistoryIncomplete ? { sourceHistoryIncomplete: true } : {}) };
|
|
348
364
|
}
|
|
349
365
|
/** Open one read-only installation subscription. Resume from the last durably applied position. */
|
|
350
366
|
export async function* watchAgentHistory(options) {
|
|
@@ -372,6 +388,89 @@ export async function* watchAgentHistory(options) {
|
|
|
372
388
|
yield historyObservation(value, frame.id, options.provider);
|
|
373
389
|
}
|
|
374
390
|
}
|
|
391
|
+
/** Subscribe at the provider's current boundary. Supply a previous cursor to validate archive ancestry. */
|
|
392
|
+
export async function* watchLiveAgentHistory(options) {
|
|
393
|
+
const idle = options.idleTimeoutMs ?? 60000;
|
|
394
|
+
if (!Number.isSafeInteger(idle) || idle < 1 || idle > 2147483647)
|
|
395
|
+
throw new AgentApiError("invalid_input", "Invalid heartbeat timeout.", 400);
|
|
396
|
+
const response = await historyResponse(options, "text/event-stream", undefined, "live");
|
|
397
|
+
let ready = false;
|
|
398
|
+
try {
|
|
399
|
+
for await (const frame of parseAgentSse(response, MAX_BYTES + 32768, idle)) {
|
|
400
|
+
const value = JSON.parse(frame.data);
|
|
401
|
+
if (!ready) {
|
|
402
|
+
if (frame.event !== "ready" || !historyObject(value) || typeof value.through !== "string" || !agentReplayCursor(value.through))
|
|
403
|
+
throw new AgentApiError("event_invalid", "The provider did not establish a live history boundary.", 502);
|
|
404
|
+
ready = true;
|
|
405
|
+
await options.onOpen?.();
|
|
406
|
+
await options.onReady(value.through);
|
|
407
|
+
}
|
|
408
|
+
else {
|
|
409
|
+
if (frame.event !== "observation")
|
|
410
|
+
throw new AgentApiError("event_invalid", "Unexpected live history frame.", 502);
|
|
411
|
+
const observation = historyObservation(value, frame.id, options.provider);
|
|
412
|
+
const transient = observation.item.kind === "event" && ["message.delta", "tool.output"].includes(observation.item.event.type);
|
|
413
|
+
if (!observation.epoch || transient !== (observation.sessionPosition === undefined))
|
|
414
|
+
throw new AgentApiError("event_invalid", "Invalid live record position.", 502);
|
|
415
|
+
yield observation;
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
finally {
|
|
420
|
+
await response.body?.cancel().catch(() => { });
|
|
421
|
+
}
|
|
422
|
+
if (!ready)
|
|
423
|
+
throw new AgentApiError("stream_closed", "The stream closed before its live boundary.", 503, true);
|
|
424
|
+
}
|
|
425
|
+
export async function readAgentHistoryStates(options) {
|
|
426
|
+
const response = await historyResponse({ ...options, cursor: undefined }, "application/json", options, "states", { afterSession: options.afterSession });
|
|
427
|
+
const page = JSON.parse(await boundedText(response, 2 * MAX_BYTES + 32768));
|
|
428
|
+
if (!historyObject(page) || !isHistoryCursor(page.through) || options.through && page.through !== options.through
|
|
429
|
+
|| !Array.isArray(page.sessions) || page.sessions.length > (options.limit ?? 100)
|
|
430
|
+
|| !(page.nextSession === null || historyIdentity(page.nextSession)))
|
|
431
|
+
throw new AgentApiError("response_invalid", "Invalid provider history state page.", 502);
|
|
432
|
+
const sessions = [];
|
|
433
|
+
let previous = options.afterSession ?? "";
|
|
434
|
+
for (const state of page.sessions) {
|
|
435
|
+
if (!historyObject(state) || !historyIdentity(state.sessionId) || state.sessionId <= previous || !historyIdentity(state.userId)
|
|
436
|
+
|| state.sourceHistoryIncomplete !== undefined && state.sourceHistoryIncomplete !== true || !historyIdentity(state.principalId) || !historyIdentity(state.epoch) || !historyPosition(state.head))
|
|
437
|
+
throw new AgentApiError("response_invalid", "Invalid provider session state.", 502);
|
|
438
|
+
validateAgentRunSnapshot(state.snapshot);
|
|
439
|
+
if (state.sessionId !== state.snapshot.sessionId || options.provider && !sameProvider(options.provider, state.snapshot.ref.provider))
|
|
440
|
+
throw new AgentApiError("response_invalid", "Provider session state identity changed.", 502);
|
|
441
|
+
previous = state.sessionId;
|
|
442
|
+
sessions.push({ sessionId: state.sessionId, userId: state.userId, principalId: state.principalId,
|
|
443
|
+
epoch: state.epoch, head: state.head, snapshot: state.snapshot, ...(state.sourceHistoryIncomplete ? { sourceHistoryIncomplete: true } : {}) });
|
|
444
|
+
}
|
|
445
|
+
if (page.nextSession !== null && (!sessions.length || page.nextSession !== previous))
|
|
446
|
+
throw new AgentApiError("response_invalid", "The history states page did not advance.", 502);
|
|
447
|
+
return { through: page.through, sessions, nextSession: page.nextSession };
|
|
448
|
+
}
|
|
449
|
+
function isHistoryCursor(value) {
|
|
450
|
+
return typeof value === "string" && Boolean(agentReplayCursor(value));
|
|
451
|
+
}
|
|
452
|
+
export async function readAgentHistoryRange(options) {
|
|
453
|
+
const { sessionId, epoch, from, to } = options;
|
|
454
|
+
if (!historyIdentity(sessionId) || !historyIdentity(epoch) || !isHistoryCursor(options.through)
|
|
455
|
+
|| !historyPosition(from) || !historyPosition(to) || to < from)
|
|
456
|
+
throw new AgentApiError("invalid_input", "Invalid session history range.", 400);
|
|
457
|
+
const response = await historyResponse({ ...options, cursor: undefined }, "application/json", options, "range", { sessionId, epoch, from, to });
|
|
458
|
+
const page = JSON.parse(await boundedText(response, 2 * MAX_BYTES + 32768));
|
|
459
|
+
if (!historyObject(page) || !Array.isArray(page.observations) || !page.observations.length || page.observations.length > (options.limit ?? 100))
|
|
460
|
+
throw new AgentApiError("response_invalid", "Invalid session history range page.", 502);
|
|
461
|
+
const observations = page.observations.map((value, index) => {
|
|
462
|
+
const item = historyObservation(value, value?.cursor, options.provider);
|
|
463
|
+
if (item.sessionId !== sessionId || item.epoch !== epoch || item.sessionPosition !== from + index || item.sessionPosition > to
|
|
464
|
+
|| item.item.kind === "event" && ["message.delta", "tool.output"].includes(item.item.event.type))
|
|
465
|
+
throw new AgentApiError("response_invalid", "Invalid durable session record or range ordering.", 502);
|
|
466
|
+
return item;
|
|
467
|
+
});
|
|
468
|
+
const next = from + observations.length;
|
|
469
|
+
const nextPosition = next <= to ? next : null;
|
|
470
|
+
if (page.nextPosition !== nextPosition)
|
|
471
|
+
throw new AgentApiError("response_invalid", "The session range page did not advance.", 502);
|
|
472
|
+
return { observations, nextPosition };
|
|
473
|
+
}
|
|
375
474
|
/** Read a bounded page at a stable installation feed position. Pass through to subsequent pages. */
|
|
376
475
|
export async function readAgentHistoryPage(options) {
|
|
377
476
|
const response = await historyResponse(options, "application/json", options);
|
package/dist/agent-schemas.js
CHANGED
|
@@ -57,6 +57,8 @@ export const AGENT_SCHEMAS = {
|
|
|
57
57
|
object({ ...baseControl, command: { const: "predictions" }, enabled: boolean }),
|
|
58
58
|
] },
|
|
59
59
|
Source: object({ agentId: id, parentAgentId: id, parentToolCallId: id }, ["agentId"]),
|
|
60
|
+
ChildAgent: object({ agentId: id, parentAgentId: id, parentToolCallId: id, state: { enum: terminalStates }, stopConfirmed: boolean,
|
|
61
|
+
prompt: { type: "string", maxLength: 65536 }, response: { type: "string", maxLength: 65536 }, promptTruncated: boolean, responseTruncated: boolean }, ["agentId", "state"], true),
|
|
60
62
|
PendingDecision: object({ id, revision, kind: { enum: ["approval", "question"] }, delivery: { enum: ["continue_run", "next_turn"] }, source: ref("Source"), title: text(65536), toolCallId: id, toolName: text(), input: {},
|
|
61
63
|
questions: list(object({ id, text: text(65536), header: text(1024), allowText: boolean, multiple: boolean, required: boolean,
|
|
62
64
|
options: list(object({ id, label: text(8192), description: text(8192), preview: text(65536) }, ["id", "label"]), 128) }, ["id", "text"]), 128) }, ["id", "revision", "kind", "delivery"], true),
|
|
@@ -68,7 +70,7 @@ export const AGENT_SCHEMAS = {
|
|
|
68
70
|
state: { enum: terminalStates }, phase: { enum: phases }, stopConfirmed: boolean, freshness: { enum: ["current", "last_known", "unavailable"] }, observedAt: { type: "string", format: "date-time" },
|
|
69
71
|
configurationRevision: revision, lastSequence: sequence, cursor: text(8192), pending: list(ref("PendingDecision"), 256),
|
|
70
72
|
effects: object({ certainty: { enum: ["known", "unknown"] }, unresolvedCallIds: unique(id, 1024) }), result: ref("Result"), messages: list(ref("Message"), 4096), tools: list(ref("Tool"), 4096),
|
|
71
|
-
agents: list(
|
|
73
|
+
agents: list(ref("ChildAgent"), 1024),
|
|
72
74
|
selection: object({ requested: ref("Selection"), effective: ref("Selection") }), admissionRef: text(),
|
|
73
75
|
coverage: object({ messages: { enum: ["complete", "truncated"] }, tools: { enum: ["complete", "truncated"] }, decisions: { enum: ["complete", "truncated"] } }, ["messages", "tools"]),
|
|
74
76
|
executionUsage: object({ sequence, activeMs: { type: "integer", minimum: 0, maximum: Number.MAX_SAFE_INTEGER }, unknown: boolean }),
|
|
@@ -77,6 +79,13 @@ export const AGENT_SCHEMAS = {
|
|
|
77
79
|
decisions: list(object({ decision: ref("PendingDecision"), state: { enum: ["pending", "resolved", "superseded", "unknown"] }, response: ref("DecisionResponse") }, ["decision", "state"]), 256),
|
|
78
80
|
pendingContinuations: list(object({ requestId: uuid, run: ref("QualifiedRef"), state: { enum: ["pending", "awaiting_authorization", "admitted", "superseded"] } }), 256) }, ["ref", "sessionId", "generation", "revision", "state", "phase", "stopConfirmed", "freshness", "observedAt", "configurationRevision", "lastSequence", "cursor", "pending", "effects"], true),
|
|
79
81
|
HistoryObservation: object(historyObservation),
|
|
82
|
+
LiveHistoryReady: object({ through: text(8192) }),
|
|
83
|
+
LiveHistoryObservation: object({ ...historyObservation, epoch: uuid, sessionPosition: positive, sourceHistoryIncomplete: { const: true } }, [...Object.keys(historyObservation), "epoch"]),
|
|
84
|
+
HistoryStates: object({ through: text(8192), nextSession: nullableText, sessions: list(object({
|
|
85
|
+
sessionId: id, userId: text(512), principalId: text(512), epoch: uuid, head: positive, snapshot: ref("RunSnapshot"), sourceHistoryIncomplete: { const: true },
|
|
86
|
+
}, ["sessionId", "userId", "principalId", "epoch", "head", "snapshot"]), 100) }),
|
|
87
|
+
HistoryRange: object({ nextPosition: { type: ["integer", "null"], minimum: 1, maximum: Number.MAX_SAFE_INTEGER },
|
|
88
|
+
observations: list(object({ ...historyObservation, cursor: text(8192), epoch: uuid, sessionPosition: positive, sourceHistoryIncomplete: { const: true } }, [...Object.keys(historyObservation), "cursor", "epoch", "sessionPosition"]), 100) }),
|
|
80
89
|
HistoryPage: object({ observations: list(object({ ...historyObservation, cursor: text(8192) }), 100),
|
|
81
90
|
through: text(8192), nextCursor: { type: ["string", "null"] } }),
|
|
82
91
|
Session: object({ ref: ref("QualifiedRef"), revision, configurationRevision: revision, configurationDigest: digest,
|
|
@@ -100,9 +109,10 @@ AGENT_SCHEMAS.Event = { ...object({ schemaVersion: { const: "agent-event.1" }, r
|
|
|
100
109
|
: name.startsWith("decision.") ? object({ decisionId: id, decision: ref("PendingDecision") }, ["decisionId"], true)
|
|
101
110
|
: name === "control.updated" ? object({ requestId: uuid, receipt: ref("ControlReceipt") }, ["requestId"], true)
|
|
102
111
|
: name === "session.bound" ? object({ sessionId: id }, ["sessionId"], true)
|
|
103
|
-
: name === "
|
|
104
|
-
: name === "
|
|
105
|
-
: {
|
|
112
|
+
: name === "agent.updated" ? object({ agent: ref("ChildAgent") }, [], true)
|
|
113
|
+
: name === "context.updated" ? object({ usage: { type: ["object", "null"], additionalProperties: true } }, ["usage"], true)
|
|
114
|
+
: name === "extension" ? object({ namespace: text(), required: { const: false }, payload: {} }, ["namespace"], true)
|
|
115
|
+
: { type: "object", additionalProperties: true } } } })),
|
|
106
116
|
};
|
|
107
117
|
const page = (key, item) => object({ [key]: list(ref(item), 100), nextCursor: { type: ["string", "null"], maxLength: 8192 } });
|
|
108
118
|
AGENT_SCHEMAS.SessionPage = page("sessions", "Session");
|
|
@@ -114,9 +124,26 @@ function operation(operationId, response, input, pathParameters = [], statuses =
|
|
|
114
124
|
return { operationId, security: [{ coreOperation: [] }], parameters: pathParameters.map(parameter), ...(input ? { requestBody: { required: true, content: { "application/json": { schema: ref(input) } } } } : {}),
|
|
115
125
|
responses: { ...errors, ...Object.fromEntries(statuses.map(status => [String(status), { description: "Authorized durable result.", headers: { "Cache-Control": { schema: { const: "no-store" } } }, content: { "application/json": { schema: ref(response) } } }])) } };
|
|
116
126
|
}
|
|
127
|
+
const historySecurity = [{ installationHistory: [] }];
|
|
128
|
+
const historyParam = (name, schema, required = false) => ({ name, in: "query", schema, required });
|
|
129
|
+
const pageLimit = historyParam("limit", { type: "integer", minimum: 1, maximum: 100 });
|
|
117
130
|
export const AGENT_OPENAPI = {
|
|
118
131
|
openapi: "3.1.0", info: { title: "Hosty Agent Execution API", version: "1.0.0", description: "Independent provider execution. Paths are relative to the current Core-declared interface base. Exact UTF-8 command bytes and stable mutation UUIDs are retained across retries. No Harness dependency or raw native session IDs." },
|
|
119
132
|
paths: {
|
|
133
|
+
"/history/live": { get: { operationId: "history.live", security: historySecurity, parameters: [historyParam("after", text(8192))],
|
|
134
|
+
description: "Open a fresh live subscription. The optional previous cursor checks archive ancestry. The ready event returns the subscribed boundary. Subsequent observation events carry an SSE id and every durable record carries its session position.",
|
|
135
|
+
responses: { ...errors, "200": { description: "Ready boundary followed by live observations.", content: {
|
|
136
|
+
"text/event-stream": { schema: { type: "string" }, "x-event-schemas": { ready: ref("LiveHistoryReady"), observation: ref("LiveHistoryObservation") } },
|
|
137
|
+
} } } } },
|
|
138
|
+
"/history/states": { get: { operationId: "history.states", security: historySecurity,
|
|
139
|
+
parameters: [historyParam("through", text(8192)), historyParam("afterSession", id), pageLimit],
|
|
140
|
+
description: "List sessions with retained runs and their state and durable session head at the supplied or current installation boundary. Pass the returned boundary on later pages.",
|
|
141
|
+
responses: { ...errors, "200": { description: "States for the calling installation.", content: { "application/json": { schema: ref("HistoryStates") } } } } } },
|
|
142
|
+
"/history/range": { get: { operationId: "history.range", security: historySecurity,
|
|
143
|
+
parameters: [historyParam("through", text(8192), true), historyParam("sessionId", id, true), historyParam("epoch", uuid, true),
|
|
144
|
+
historyParam("from", positive, true), historyParam("to", positive, true), pageLimit],
|
|
145
|
+
description: "Read an inclusive interval of durable positions for one session and history epoch. nextPosition is the first unread position in the requested interval.",
|
|
146
|
+
responses: { ...errors, "200": { description: "Ordered durable session records.", content: { "application/json": { schema: ref("HistoryRange") } } } } } },
|
|
120
147
|
"/history/events": { get: { operationId: "history.events", security: [{ installationHistory: [] }],
|
|
121
148
|
parameters: [{ name: "after", in: "query", schema: text(8192) }, { name: "through", in: "query", schema: text(8192) }, { name: "limit", in: "query", schema: { type: "integer", minimum: 1, maximum: 100 } }],
|
|
122
149
|
description: "Resumable, read-only installation history. Frames use event: observation with an opaque installation feed position in id. Commit each observation before saving this position.",
|
package/dist/agent-server.js
CHANGED
|
@@ -420,6 +420,13 @@ function finiteJson(value, depth = 0, seen = new Set()) {
|
|
|
420
420
|
function contextUsage(value) { return value === null || object(value) && finiteJson(value); }
|
|
421
421
|
function source(value) { if (!object(value) || !opaque(value.agentId) || value.parentAgentId !== undefined && !opaque(value.parentAgentId) || value.parentToolCallId !== undefined && (!opaque(value.parentToolCallId) || !opaque(value.parentAgentId)))
|
|
422
422
|
responseProblem("Invalid execution source."); }
|
|
423
|
+
function validateChildAgent(agent) {
|
|
424
|
+
source(agent);
|
|
425
|
+
if (!object(agent) || !["queued", "running", "waiting_for_input", "succeeded", "failed", "cancelled", "unknown"].includes(String(agent.state))
|
|
426
|
+
|| [agent.stopConfirmed, agent.promptTruncated, agent.responseTruncated].some(flag => flag !== undefined && typeof flag !== "boolean")
|
|
427
|
+
|| [agent.prompt, agent.response].some(text => text !== undefined && (typeof text !== "string" || text.length > 65536 && [...text].length > 65536)))
|
|
428
|
+
responseProblem("Invalid child agent observation.");
|
|
429
|
+
}
|
|
423
430
|
export function validateAgentPendingDecision(value) {
|
|
424
431
|
if (!object(value) || !opaque(value.id) || !decimal(value.revision) || !["approval", "question"].includes(String(value.kind)) || !["continue_run", "next_turn"].includes(String(value.delivery)))
|
|
425
432
|
responseProblem("Invalid pending decision.");
|
|
@@ -509,11 +516,8 @@ export function validateAgentRunSnapshot(value) {
|
|
|
509
516
|
}
|
|
510
517
|
if (value.agents !== undefined) {
|
|
511
518
|
array(value.agents, 1024, "agent inventory");
|
|
512
|
-
for (const agent of value.agents)
|
|
513
|
-
|
|
514
|
-
if (!object(agent) || !["queued", "running", "waiting_for_input", "succeeded", "failed", "cancelled", "unknown"].includes(String(agent.state)) || agent.stopConfirmed !== undefined && typeof agent.stopConfirmed !== "boolean")
|
|
515
|
-
responseProblem("Invalid retained child agent state.");
|
|
516
|
-
}
|
|
519
|
+
for (const agent of value.agents)
|
|
520
|
+
validateChildAgent(agent);
|
|
517
521
|
}
|
|
518
522
|
if (Buffer.byteLength(JSON.stringify(value)) > AGENT_COMMAND_MAX_BYTES)
|
|
519
523
|
responseProblem("Snapshot byte allowance exceeded.");
|
|
@@ -544,6 +548,8 @@ export function validateAgentEvent(value) {
|
|
|
544
548
|
responseProblem("Context events require nullable JSON observation data.");
|
|
545
549
|
else if (value.type === "extension" && (!bounded(data.namespace, 256) || data.required === true))
|
|
546
550
|
responseProblem("Extensions cannot carry required protocol semantics.");
|
|
551
|
+
if (value.type === "agent.updated" && data.agent !== undefined)
|
|
552
|
+
validateChildAgent(data.agent);
|
|
547
553
|
if (data.decision !== undefined)
|
|
548
554
|
validateAgentPendingDecision(data.decision);
|
|
549
555
|
if (data.response !== undefined) {
|
package/dist/agent.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ export declare const AGENT_API_VERSION: 1;
|
|
|
7
7
|
export declare const AGENT_EVENT_VERSION: "agent-event.1";
|
|
8
8
|
export declare const AGENT_CAPABILITIES: {
|
|
9
9
|
readonly installationHistory: "installation-history";
|
|
10
|
+
readonly liveInstallationHistory: "installation-history.live";
|
|
10
11
|
readonly resume: "session.resume";
|
|
11
12
|
readonly configuration: "configuration.resume-compatible";
|
|
12
13
|
readonly images: "input.images";
|
|
@@ -321,6 +322,11 @@ export type AgentRunSnapshot = {
|
|
|
321
322
|
agents?: Array<AgentSource & {
|
|
322
323
|
state: AgentRunState;
|
|
323
324
|
stopConfirmed?: boolean;
|
|
325
|
+
/** Native assignment and final answer, when the provider can attribute them to this child. */
|
|
326
|
+
prompt?: string;
|
|
327
|
+
response?: string;
|
|
328
|
+
promptTruncated?: boolean;
|
|
329
|
+
responseTruncated?: boolean;
|
|
324
330
|
}>;
|
|
325
331
|
selection?: {
|
|
326
332
|
requested: {
|
|
@@ -462,6 +468,18 @@ export type AgentHistoryObservation = {
|
|
|
462
468
|
principalId: string;
|
|
463
469
|
item: AgentWatchItem;
|
|
464
470
|
cursor: string;
|
|
471
|
+
epoch?: string;
|
|
472
|
+
sessionPosition?: number;
|
|
473
|
+
sourceHistoryIncomplete?: true;
|
|
474
|
+
};
|
|
475
|
+
export type AgentHistorySessionState = {
|
|
476
|
+
sessionId: string;
|
|
477
|
+
userId: string;
|
|
478
|
+
principalId: string;
|
|
479
|
+
epoch: string;
|
|
480
|
+
head: number;
|
|
481
|
+
snapshot: AgentRunSnapshot;
|
|
482
|
+
sourceHistoryIncomplete?: true;
|
|
465
483
|
};
|
|
466
484
|
export type AgentErrorDetail = {
|
|
467
485
|
code: string;
|
package/dist/agent.js
CHANGED
|
@@ -2,6 +2,7 @@ export const AGENT_API_VERSION = 1;
|
|
|
2
2
|
export const AGENT_EVENT_VERSION = "agent-event.1";
|
|
3
3
|
export const AGENT_CAPABILITIES = {
|
|
4
4
|
installationHistory: "installation-history",
|
|
5
|
+
liveInstallationHistory: "installation-history.live",
|
|
5
6
|
resume: "session.resume", configuration: "configuration.resume-compatible", images: "input.images",
|
|
6
7
|
noNativeTools: "native-tools.none", skills: "skills.catalog", exclusiveSkills: "skills.exclusive-selection",
|
|
7
8
|
coreMcp: "mcp.core", externalMcp: "mcp.external", modelChange: "model.change-on-resume",
|
package/package.json
CHANGED