@gea-ai/agent-sdk 0.1.260923-alpha.2 → 0.1.260923-alpha.4

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.
@@ -500,17 +500,31 @@ export async function handleAgentSessionInboxRequest(request, storage) {
500
500
  if (!storage.setAlarm || !storage.deleteAlarm)
501
501
  return Response.json({ error: "session_alarms_unavailable" }, { status: 503 });
502
502
  const body = await request.json();
503
+ const admission = path === "/v1/inbox/start" || path === "/v1/inbox/enter"
504
+ ? agentSessionBootstrapSchema
505
+ .extend({
506
+ executionId: z.uuid(),
507
+ runId: z.uuid().optional(),
508
+ message: agentSessionSendSchema.optional(),
509
+ continuation: agentApplicationAssistantMessageSchema.optional(),
510
+ traceContext: traceContextSchema.optional(),
511
+ metadata: studioChatMetadataSchema.optional(),
512
+ })
513
+ .refine((input) => Boolean(input.message) !== Boolean(input.continuation), "Enter requires one message or validated continuation.")
514
+ .parse(body)
515
+ : undefined;
503
516
  return storage.transaction(async (tx) => {
504
- const state = await readState(tx);
505
- if (path === "/v1/inbox/initialize") {
506
- const identity = agentSessionIdentitySchema.parse(body);
517
+ let state = await readState(tx);
518
+ if (path === "/v1/inbox/initialize" ||
519
+ (!state && path === "/v1/inbox/start")) {
520
+ const identity = admission?.identity ?? agentSessionIdentitySchema.parse(body);
507
521
  if (state)
508
522
  return canonicalAgentChannelJson(state.identity) ===
509
523
  canonicalAgentChannelJson(identity)
510
524
  ? Response.json({ initialized: true })
511
525
  : Response.json({ error: "session_identity_conflict" }, { status: 409 });
512
526
  await readChildRunIndex(tx);
513
- await writeState(tx, {
527
+ state = {
514
528
  identity,
515
529
  messages: [],
516
530
  execution: null,
@@ -525,8 +539,11 @@ export async function handleAgentSessionInboxRequest(request, storage) {
525
539
  draining: null,
526
540
  terminalQueue: [],
527
541
  pendingStarts: [],
528
- });
529
- return Response.json({ initialized: true });
542
+ };
543
+ if (path === "/v1/inbox/initialize") {
544
+ await writeState(tx, state);
545
+ return Response.json({ initialized: true });
546
+ }
530
547
  }
531
548
  if (!state)
532
549
  return Response.json({ error: "session_not_initialized" }, { status: 409 });
@@ -542,25 +559,26 @@ export async function handleAgentSessionInboxRequest(request, storage) {
542
559
  .filter((entry) => entry.mode === "follow_up" && !entry.id.startsWith("run:"))
543
560
  .map(({ id, message }) => ({ id, message })),
544
561
  });
562
+ case "start":
545
563
  case "enter": {
546
564
  if (await activeComputerOperation(tx))
547
565
  return Response.json({ error: "computer_busy" }, { status: 409 });
548
- const input = agentSessionBootstrapSchema
549
- .extend({
550
- executionId: z.uuid(),
551
- runId: z.uuid().optional(),
552
- message: agentSessionSendSchema.optional(),
553
- continuation: agentApplicationAssistantMessageSchema.optional(),
554
- traceContext: traceContextSchema.optional(),
555
- metadata: studioChatMetadataSchema.optional(),
556
- })
557
- .refine((input) => Boolean(input.message) !== Boolean(input.continuation), "Enter requires one message or validated continuation.")
558
- .parse(body);
566
+ const input = admission;
559
567
  if (canonicalAgentChannelJson(state.identity) !==
560
568
  canonicalAgentChannelJson(input.identity))
561
569
  return Response.json({ error: "session_identity_conflict" }, { status: 409 });
562
- if (state.execution?.id === input.executionId)
570
+ if (state.execution?.id === input.executionId) {
571
+ if (path === "/v1/inbox/start") {
572
+ if (state.started)
573
+ return Response.json({ error: "execution_already_started" }, {
574
+ status: 409,
575
+ headers: { "x-gea-session-execution": "already-started" },
576
+ });
577
+ state.started = true;
578
+ await save(tx, state, runs);
579
+ }
563
580
  return Response.json({ execution: state.execution });
581
+ }
564
582
  if (state.execution ||
565
583
  state.draining ||
566
584
  state.terminalQueue.length >= 8 ||
@@ -613,7 +631,7 @@ export async function handleAgentSessionInboxRequest(request, storage) {
613
631
  state.resumeWait = null;
614
632
  if (!state.draining)
615
633
  state.stopped = false;
616
- state.started = false;
634
+ state.started = path === "/v1/inbox/start";
617
635
  if (input.message)
618
636
  await tx.put(`inbox:message:${input.message.id}`, input.message);
619
637
  await save(tx, state, runs);
@@ -102,6 +102,10 @@ type AgentApplicationDefinition = {
102
102
  skillMount?: AgentWorkerSkillMount;
103
103
  subagents?: Record<string, AgentApplicationDefinition>;
104
104
  };
105
+ type AgentStartupTiming = {
106
+ startedAt: number;
107
+ phases: Record<string, number>;
108
+ };
105
109
  export declare function composeFetch<TEnvironment, TContext>(...handlers: ReadonlyArray<ComposableFetch<TEnvironment, TContext>>): (request: Request, environment: TEnvironment, context: TContext) => Promise<Response>;
106
110
  export declare function createAgentFetch<TEnvironment extends AgentFetchEnvironment = AgentFetchEnvironment, TContext = unknown>(definition: DefinedAgentPackage): ComposableFetch<TEnvironment, TContext>;
107
111
  /**
@@ -192,6 +196,8 @@ export type AgentSessionNamespace = {
192
196
  idFromName(name: string): unknown;
193
197
  };
194
198
  export declare function runAgentWorkerRequest(input: {
199
+ startup?: AgentStartupTiming;
200
+ inboxStarted?: boolean;
195
201
  interactionPolicy?: AgentInteractionPolicy;
196
202
  initialization?: AgentWorkerToolInitialization;
197
203
  inboxExecution?: AgentSessionInboxExecution;