@gea-ai/agent-sdk 0.1.261014-alpha.0 → 0.1.261016-alpha.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.
Files changed (40) hide show
  1. package/dist/agent-call.d.ts +3 -3
  2. package/dist/agent-channel-api.js +28 -3
  3. package/dist/agent-channel-author-runtime.d.ts +2 -2
  4. package/dist/agent-channel-author-runtime.js +38 -1
  5. package/dist/agent-channel-runtime.d.ts +1 -1
  6. package/dist/agent-channel-runtime.js +210 -160
  7. package/dist/agent-channel-session-transport.d.ts +3 -0
  8. package/dist/agent-channel-session-transport.js +26 -0
  9. package/dist/agent-client-tool.d.ts +3 -0
  10. package/dist/agent-client-tool.js +79 -0
  11. package/dist/agent-computer-http.js +2 -2
  12. package/dist/agent-core.wasm +0 -0
  13. package/dist/agent-remote-run.d.ts +2 -2
  14. package/dist/agent-run-host.d.ts +6 -6
  15. package/dist/agent-session-execution.js +20 -0
  16. package/dist/agent-session-inbox.d.ts +1 -1
  17. package/dist/agent-session-inbox.js +318 -23
  18. package/dist/agent-session-runner.d.ts +0 -2
  19. package/dist/agent-session-runner.js +0 -28
  20. package/dist/agent-session.d.ts +10 -0
  21. package/dist/agent-session.js +8 -61
  22. package/dist/agent-stream-coalescing.js +2 -1
  23. package/dist/agent-worker-attachments.d.ts +2 -2
  24. package/dist/agent-worker.d.ts +5 -3
  25. package/dist/agent-worker.js +415 -648
  26. package/dist/artifacts.d.ts +4 -4
  27. package/dist/artifacts.js +2 -2
  28. package/dist/channels/index.d.ts +7 -2
  29. package/dist/experimental/agent-core-ui.js +1 -0
  30. package/dist/index.d.ts +9 -4
  31. package/dist/index.js +6 -0
  32. package/dist/session-authority.d.ts +1 -1
  33. package/dist/tool-model-output.d.ts +1 -1
  34. package/dist/version.d.ts +1 -1
  35. package/dist/version.js +1 -1
  36. package/package.json +6 -2
  37. package/dist/agent-session-authority.d.ts +0 -7
  38. package/dist/agent-session-authority.js +0 -1127
  39. package/dist/agent-session-executor.d.ts +0 -518
  40. package/dist/agent-session-executor.js +0 -293
@@ -1,12 +1,12 @@
1
1
  import { z } from "zod";
2
2
  import { type AgentWorkerToolInitialization } from "@gea-ai/contract/agent-worker-tools";
3
3
  import type { AgentHostBinding } from "./agent-worker.js";
4
- import type { StudioArtifactScope } from "@gea-ai/contract/studio-artifacts";
4
+ import type { BuilderArtifactScope } from "@gea-ai/contract/builder-artifacts";
5
5
  /** Fresh Sessions keep the declared-target rule. A resume only needs sessionId. */
6
6
  export declare function workerAgentToolInputSchema(input: {
7
7
  agents: NonNullable<AgentWorkerToolInitialization["agents"]>;
8
8
  canCopy?: boolean;
9
- artifactScope?: StudioArtifactScope;
9
+ artifactScope?: BuilderArtifactScope;
10
10
  }): z.ZodObject<{
11
11
  sessionId: z.ZodOptional<z.ZodUUID>;
12
12
  target: z.ZodOptional<z.ZodString>;
@@ -33,7 +33,7 @@ export declare function createWorkerAgentTool(input: {
33
33
  host: AgentHostBinding;
34
34
  runId?: string;
35
35
  canCopy?: boolean;
36
- artifactScope?: StudioArtifactScope;
36
+ artifactScope?: BuilderArtifactScope;
37
37
  }): ({
38
38
  deferLoading?: boolean;
39
39
  title?: string;
@@ -27,16 +27,41 @@ export function extractChannelReply(messageValue, responseMessageId) {
27
27
  .filter((part) => part.type === "text")
28
28
  .map((part) => part.text ?? "")
29
29
  .join("");
30
+ const authorizationUrls = new Set();
30
31
  for (const part of message.parts) {
31
32
  if (!(part.type.startsWith("tool-") || part.type === "dynamic-tool") ||
32
33
  part.state !== "output-available")
33
34
  continue;
34
35
  const authorization = z
35
- .object({ status: z.literal("authorization_required"), url: z.url() })
36
+ .object({
37
+ status: z.enum(["authorization_required", "authorization_available"]),
38
+ url: z.url(),
39
+ })
36
40
  .safeParse(part.output);
37
- if (authorization.success && !text.includes(authorization.data.url))
38
- text += `${text ? "\n\n" : ""}${authorization.data.url}`;
41
+ if (authorization.success)
42
+ authorizationUrls.add(authorization.data.url);
39
43
  }
44
+ if (authorizationUrls.size === 0)
45
+ return { messageId: responseMessageId, text };
46
+ const authorizationEndpoints = new Set([...authorizationUrls].map((value) => {
47
+ const url = new URL(value);
48
+ return `${url.origin}${url.pathname}`;
49
+ }));
50
+ const isRewrittenAuthorizationUrl = (value) => {
51
+ if (authorizationUrls.has(value) || !URL.canParse(value))
52
+ return false;
53
+ const url = new URL(value);
54
+ return authorizationEndpoints.has(`${url.origin}${url.pathname}`);
55
+ };
56
+ // Models can corrupt opaque tickets while copying them. Remove those links
57
+ // before appending the original tool URLs; never leave a broken link first.
58
+ text = text
59
+ .replace(/\[([^\]\n]*)\]\((https?:\/\/[^\s)]+)\)/gu, (link, label, url) => isRewrittenAuthorizationUrl(url) ? label : link)
60
+ .replace(/https?:\/\/[^\s<>)]+/gu, (url) => isRewrittenAuthorizationUrl(url) ? "" : url)
61
+ .trim();
62
+ for (const url of authorizationUrls)
63
+ if (!text.includes(url))
64
+ text += `${text ? "\n\n" : ""}${url}`;
40
65
  return { messageId: responseMessageId, text };
41
66
  }
42
67
  /** Channel owns delivery; ordinary Agents API owns admission, execution and history. */
@@ -1,5 +1,5 @@
1
1
  import { type AgentChannelInvocationContext } from "@gea-ai/contract/agent-channels";
2
- import { type AgentChannelRuntimeCommand, type AgentChannelRuntimeStart, type AgentChannelJson } from "@gea-ai/contract/agent-channel-runtime";
2
+ import { type AgentChannelRuntimeCommand, type AgentChannelRuntimeEnqueue, type AgentChannelJson } from "@gea-ai/contract/agent-channel-runtime";
3
3
  import type { AgentChannelFetchEnvironment } from "./agent-worker.js";
4
4
  import type { AnyDefinedChannel, ChannelCapabilities, ChannelInputContext, ChannelRouteContext, ChannelWebSocketRoute } from "./channels/index.js";
5
5
  export declare function createChannelCapabilities(environment: AgentChannelFetchEnvironment, signal: AbortSignal): Promise<ChannelCapabilities>;
@@ -15,7 +15,7 @@ export declare function createChannelRouteContext(input: Parameters<typeof creat
15
15
  /** Only the retained Worker definition interprets state and executes event/outbound code. */
16
16
  export declare function executeChannelBehavior(input: {
17
17
  definition: AnyDefinedChannel;
18
- command: Exclude<AgentChannelRuntimeCommand, AgentChannelRuntimeStart>;
18
+ command: Exclude<AgentChannelRuntimeCommand, AgentChannelRuntimeEnqueue>;
19
19
  environment: AgentChannelFetchEnvironment;
20
20
  signal: AbortSignal;
21
21
  }): Promise<{
@@ -3,7 +3,7 @@ import { readChannelSessionHistory } from "./agent-channel-api.js";
3
3
  import { z } from "zod";
4
4
  import { validateUIMessages } from "ai";
5
5
  import { createAgentChannelStableId, agentChannelUserIdentitySchema, agentChannelAddressSchema, agentChannelExecutionTargetSchema, } from "@gea-ai/contract/agent-channels";
6
- import { agentChannelInputSchema, agentChannelEventSchema, agentChannelJournalPageSchema, agentChannelJsonSchema, agentChannelOutboundResultSchema, agentChannelRuntimeProjectionSchema, } from "@gea-ai/contract/agent-channel-runtime";
6
+ import { agentChannelInputSchema, agentChannelOutputInputSchema, agentChannelOutputReceiptSchema, agentChannelEventSchema, agentChannelJournalPageSchema, agentChannelJsonSchema, agentChannelOutboundResultSchema, agentChannelRuntimeProjectionSchema, } from "@gea-ai/contract/agent-channel-runtime";
7
7
  import { ChannelInputError } from "./channels/index.js";
8
8
  const HOST = "/internal/agent-worker-host/v1/channel";
9
9
  const initializationSchema = z.object({
@@ -23,6 +23,8 @@ const sessionSchema = z
23
23
  })
24
24
  .nullable();
25
25
  const receiptSchema = z.object({
26
+ runId: z.uuid(),
27
+ inputId: z.string().min(1),
26
28
  conversationId: z.string(),
27
29
  duplicate: z.boolean(),
28
30
  executionTarget: agentChannelExecutionTargetSchema,
@@ -289,6 +291,41 @@ export async function createChannelInputContext(input) {
289
291
  from(raw, value, sessionOptions) {
290
292
  const identity = agentChannelUserIdentitySchema.parse(value);
291
293
  return {
294
+ async enqueueOutput(key, payload, options) {
295
+ if (!input.definition.outbound)
296
+ throw new Error("Channel output requires an outbound handler.");
297
+ await authorize();
298
+ await authorizeUser(identity);
299
+ const address = await getAddress(raw, identity.principal, sessionOptions);
300
+ const normalized = agentChannelOutputInputSchema.parse({
301
+ principal: identity.principal,
302
+ authorization: identity.authorization,
303
+ operationId: await createAgentChannelStableId("external-event", address.installationId, address.agentKey, address.channelKey, options.operationId),
304
+ outbox: {
305
+ key,
306
+ payload: input.definition.outboundSchema
307
+ ? input.definition.outboundSchema.parse(payload)
308
+ : payload,
309
+ },
310
+ ...(input.definition.idempotencyWindowMs
311
+ ? { idempotencyWindowMs: input.definition.idempotencyWindowMs }
312
+ : {}),
313
+ });
314
+ return agentChannelOutputReceiptSchema.parse(await addressRequest(input.environment, address, "/v2/ingress", {
315
+ address,
316
+ channelPath: input.definition.path,
317
+ executionTarget: await getExecutionTarget(address),
318
+ input: normalized,
319
+ ...(input.identity.receiverRevision === undefined
320
+ ? {}
321
+ : {
322
+ receiver: {
323
+ installationId: input.identity.installationId,
324
+ revision: input.identity.receiverRevision,
325
+ },
326
+ }),
327
+ }, input.signal));
328
+ },
292
329
  async send(message, options) {
293
330
  return send(await getAddress(raw, identity.principal, sessionOptions), identity, message, options);
294
331
  },
@@ -1,5 +1,5 @@
1
1
  import type { AgentChannelAddressStorage, AgentChannelAddressEnvironment } from "./agent-channel-worker.js";
2
2
  /** An accepted operation owns its code target; the address owns only stable session state. */
3
- export declare function handleCustomChannelAddressRequest(request: Request, storage: AgentChannelAddressStorage, _environment?: AgentChannelAddressEnvironment): Promise<Response>;
3
+ export declare function handleCustomChannelAddressRequest(request: Request, storage: AgentChannelAddressStorage, environment?: AgentChannelAddressEnvironment): Promise<Response>;
4
4
  /** Input execution, event projection, and delivery advance independently on durable alarms. */
5
5
  export declare function handleCustomChannelAddressAlarm(storage: AgentChannelAddressStorage, environment: AgentChannelAddressEnvironment): Promise<void>;