@dual-os/sdk 0.8.0-next.3 → 0.8.1
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/AgentChannel.d.ts +42 -7
- package/dist/AgentChannel.d.ts.map +1 -1
- package/dist/AgentChannel.js +17 -7
- package/dist/AgentChannel.js.map +1 -1
- package/dist/AgentChannelRuntime.js +2 -2
- package/dist/AgentChannelRuntime.js.map +1 -1
- package/package.json +1 -1
- package/src/AgentChannel.ts +24 -8
- package/src/AgentChannelRuntime.ts +4 -2
package/dist/AgentChannel.d.ts
CHANGED
|
@@ -21,7 +21,10 @@ export declare const Features: Schema.Struct<{
|
|
|
21
21
|
/** Maximum Unicode code points per physical text message, including server-added prefixes. */
|
|
22
22
|
readonly maxTextLength: Schema.optionalKey<Schema.Int>;
|
|
23
23
|
readonly mentions: Schema.Boolean;
|
|
24
|
-
/**
|
|
24
|
+
/**
|
|
25
|
+
* The output operations every destination of this version shows. Every definition declares
|
|
26
|
+
* them; retired catalog contracts that predate them still decode.
|
|
27
|
+
*/
|
|
25
28
|
readonly operations: Schema.optionalKey<Schema.$Array<Schema.Literals<readonly ["present_outcome", "create_message", "update_message", "delete_message", "set_reaction", "set_activity", "render_plan"]>>>;
|
|
26
29
|
/** Whether `read_context` returns the conversation's earlier messages. */
|
|
27
30
|
readonly readContext: Schema.optionalKey<Schema.Boolean>;
|
|
@@ -286,15 +289,19 @@ export declare const Operation: Schema.Union<readonly [Schema.Struct<{
|
|
|
286
289
|
readonly revision: Schema.Int;
|
|
287
290
|
}>]>;
|
|
288
291
|
export type Operation = typeof Operation.Type;
|
|
289
|
-
/** A message read back from
|
|
292
|
+
/** A message read back from history; `assets` only where a version declares assets and context. */
|
|
290
293
|
export declare const ContextMessage: Schema.Struct<{
|
|
291
294
|
readonly messageKey: Schema.NonEmptyString;
|
|
292
|
-
/** The agent's own message. */
|
|
293
295
|
readonly own: Schema.Boolean;
|
|
294
296
|
readonly senderKey: Schema.NonEmptyString;
|
|
295
297
|
readonly senderName: Schema.optionalKey<Schema.NonEmptyString>;
|
|
296
298
|
readonly text: Schema.String;
|
|
297
299
|
readonly timestamp: Schema.String;
|
|
300
|
+
readonly assets: Schema.optionalKey<Schema.$Array<Schema.Struct<{
|
|
301
|
+
readonly assetKey: Schema.NonEmptyString;
|
|
302
|
+
readonly mediaType: Schema.NonEmptyString;
|
|
303
|
+
readonly url: Schema.String;
|
|
304
|
+
}>>>;
|
|
298
305
|
}>;
|
|
299
306
|
export type ContextMessage = typeof ContextMessage.Type;
|
|
300
307
|
/** Decoded originals are limited separately by the host; ordinary command JSON stays bounded. */
|
|
@@ -441,7 +448,8 @@ export declare const commandSchema: <State extends Schema.Top>(state: State) =>
|
|
|
441
448
|
readonly operationKey: Schema.NonEmptyString;
|
|
442
449
|
readonly state: State;
|
|
443
450
|
}>]>;
|
|
444
|
-
|
|
451
|
+
/** Pass a version's features to check its results against its own contract. */
|
|
452
|
+
export declare const resultSchema: <State extends Schema.Top>(state: State, features?: Features) => Schema.Union<readonly [Schema.Union<readonly [Schema.Struct<{
|
|
445
453
|
readonly extensions: Schema.optionalKey<Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>>;
|
|
446
454
|
readonly operationKey: Schema.NonEmptyString;
|
|
447
455
|
readonly kind: Schema.Literal<"activate">;
|
|
@@ -551,13 +559,25 @@ export declare const resultSchema: <State extends Schema.Top>(state: State) => S
|
|
|
551
559
|
readonly operationKey: Schema.NonEmptyString;
|
|
552
560
|
readonly kind: Schema.Literal<"read_context">;
|
|
553
561
|
readonly messages: Schema.$Array<Schema.Struct<{
|
|
554
|
-
|
|
562
|
+
messageKey: Schema.NonEmptyString;
|
|
555
563
|
/** The agent's own message. */
|
|
564
|
+
own: Schema.Boolean;
|
|
565
|
+
senderKey: Schema.NonEmptyString;
|
|
566
|
+
senderName: Schema.optionalKey<Schema.NonEmptyString>;
|
|
567
|
+
text: Schema.String;
|
|
568
|
+
timestamp: Schema.String;
|
|
569
|
+
}> | Schema.Struct<{
|
|
570
|
+
readonly messageKey: Schema.NonEmptyString;
|
|
556
571
|
readonly own: Schema.Boolean;
|
|
557
572
|
readonly senderKey: Schema.NonEmptyString;
|
|
558
573
|
readonly senderName: Schema.optionalKey<Schema.NonEmptyString>;
|
|
559
574
|
readonly text: Schema.String;
|
|
560
575
|
readonly timestamp: Schema.String;
|
|
576
|
+
readonly assets: Schema.optionalKey<Schema.$Array<Schema.Struct<{
|
|
577
|
+
readonly assetKey: Schema.NonEmptyString;
|
|
578
|
+
readonly mediaType: Schema.NonEmptyString;
|
|
579
|
+
readonly url: Schema.String;
|
|
580
|
+
}>>>;
|
|
561
581
|
}>>;
|
|
562
582
|
}>]>, Schema.Struct<{
|
|
563
583
|
readonly assetKey: Schema.NonEmptyString;
|
|
@@ -691,13 +711,25 @@ export declare const CheckedResult: Schema.Union<readonly [Schema.Union<readonly
|
|
|
691
711
|
readonly operationKey: Schema.NonEmptyString;
|
|
692
712
|
readonly kind: Schema.Literal<"read_context">;
|
|
693
713
|
readonly messages: Schema.$Array<Schema.Struct<{
|
|
694
|
-
|
|
714
|
+
messageKey: Schema.NonEmptyString;
|
|
695
715
|
/** The agent's own message. */
|
|
716
|
+
own: Schema.Boolean;
|
|
717
|
+
senderKey: Schema.NonEmptyString;
|
|
718
|
+
senderName: Schema.optionalKey<Schema.NonEmptyString>;
|
|
719
|
+
text: Schema.String;
|
|
720
|
+
timestamp: Schema.String;
|
|
721
|
+
}> | Schema.Struct<{
|
|
722
|
+
readonly messageKey: Schema.NonEmptyString;
|
|
696
723
|
readonly own: Schema.Boolean;
|
|
697
724
|
readonly senderKey: Schema.NonEmptyString;
|
|
698
725
|
readonly senderName: Schema.optionalKey<Schema.NonEmptyString>;
|
|
699
726
|
readonly text: Schema.String;
|
|
700
727
|
readonly timestamp: Schema.String;
|
|
728
|
+
readonly assets: Schema.optionalKey<Schema.$Array<Schema.Struct<{
|
|
729
|
+
readonly assetKey: Schema.NonEmptyString;
|
|
730
|
+
readonly mediaType: Schema.NonEmptyString;
|
|
731
|
+
readonly url: Schema.String;
|
|
732
|
+
}>>>;
|
|
701
733
|
}>>;
|
|
702
734
|
}>]>, Schema.Struct<{
|
|
703
735
|
readonly assetKey: Schema.NonEmptyString;
|
|
@@ -729,7 +761,10 @@ export declare const Contract: Schema.Struct<{
|
|
|
729
761
|
/** Maximum Unicode code points per physical text message, including server-added prefixes. */
|
|
730
762
|
readonly maxTextLength: Schema.optionalKey<Schema.Int>;
|
|
731
763
|
readonly mentions: Schema.Boolean;
|
|
732
|
-
/**
|
|
764
|
+
/**
|
|
765
|
+
* The output operations every destination of this version shows. Every definition declares
|
|
766
|
+
* them; retired catalog contracts that predate them still decode.
|
|
767
|
+
*/
|
|
733
768
|
readonly operations: Schema.optionalKey<Schema.$Array<Schema.Literals<readonly ["present_outcome", "create_message", "update_message", "delete_message", "set_reaction", "set_activity", "render_plan"]>>>;
|
|
734
769
|
/** Whether `read_context` returns the conversation's earlier messages. */
|
|
735
770
|
readonly readContext: Schema.optionalKey<Schema.Boolean>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AgentChannel.d.ts","names":["AuthMethod.Any","AuthMethod.Value"],"sources":["../src/AgentChannel.ts"],"mappings":";;;;;;qBASa;YACD,gBAAgB;;qBAGf,KAAG,OAAA;;qBAKH,eAAa,OAAA;YASd,uBAAuB,cAAc;qBACpC,UAAQ,OAAA
|
|
1
|
+
{"version":3,"file":"AgentChannel.d.ts","names":["AuthMethod.Any","AuthMethod.Value"],"sources":["../src/AgentChannel.ts"],"mappings":";;;;;;qBASa;YACD,gBAAgB;;qBAGf,KAAG,OAAA;;qBAKH,eAAa,OAAA;YASd,uBAAuB,cAAc;qBACpC,UAAQ,OAAA;;;;;;;;;;;;;;;;;;;;;;YAsBT,kBAAkB,SAAS;qBAqB1B,aAAW,OAAA;;;;;YAKZ,qBAAqB,YAAY;qBAChC,OAAK,OAAA;;;;;qBAKL,S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,aAAa,yBAAyBA,WAChD,+BAA8B,KAC1B,UAAUA;WACG,UAAU;WAA0B,OAAOC,MAAiB;;YAGnE,eAAe,UAAU;WAC1B,oBAAoB;WACpB,oBAAoB;KAC1B,2DAEc;WACF,OAAO,aAAa;;WACpB,MAAM,aAAa;;;YAExB,WAAW,UAAU,cAAc,QAAQ;;YAE3C,UAAU,UAAU,cAAc,OAAO;iBACpC,gBAAgB,UAAU,YAAY;WAC5C,SACP,SAAS,SACT,SAAS,eAAe,OACrB,OAAO,OAAO,cAAc,cAAc;WACtC,cACP,UAAU,kBACV,SAAS,eAAe,OACrB,OAAO,OAAO,eAAe,cAAc;WACvC,UACP,SAAS,WAAW,IACpB,SAAS,eAAe,OACrB,OAAO,OAAO,UAAU,IAAI,cAAc;;;iBAGhC,QAAQ;WACd,WAAW;WACX,SAAS,QAAQ;WACjB;aACE,SACP,kBACA,qBACG,OAAO;aACH,cACP,mBACA,qBACG,OAAO;aACH,UACP,kBACA,qBACG,OAAO;;;qBAGH,aAAU;;qBAmFV,qBAAkB,YACjB,YAAU,qBACH,mBACAD;iBAyCJ;WACN;WACA;;;qBAIE,aAAc,yBAAyB,UAAU,aAAa,gBAAc,YAC3E,IAAE,SACL,MACR,aAAa,IAAI;qBAqBP,iBAAc,mBAAqB,SAAS"}
|
package/dist/AgentChannel.js
CHANGED
|
@@ -73,7 +73,10 @@ const Features = Schema.Struct({
|
|
|
73
73
|
/** Maximum Unicode code points per physical text message, including server-added prefixes. */
|
|
74
74
|
maxTextLength: Schema.optionalKey(Schema.Int.check(Schema.isGreaterThan(0))),
|
|
75
75
|
mentions: Schema.Boolean,
|
|
76
|
-
/**
|
|
76
|
+
/**
|
|
77
|
+
* The output operations every destination of this version shows. Every definition declares
|
|
78
|
+
* them; retired catalog contracts that predate them still decode.
|
|
79
|
+
*/
|
|
77
80
|
operations: Schema.optionalKey(Schema.Array(OperationKind)),
|
|
78
81
|
/** Whether `read_context` returns the conversation's earlier messages. */
|
|
79
82
|
readContext: Schema.optionalKey(Schema.Boolean),
|
|
@@ -279,8 +282,7 @@ const Operation = Schema.Union([
|
|
|
279
282
|
revision: Schema.Int.check(Schema.isGreaterThan(0))
|
|
280
283
|
})
|
|
281
284
|
]);
|
|
282
|
-
|
|
283
|
-
const ContextMessage = Schema.Struct({
|
|
285
|
+
const contextMessageFields = {
|
|
284
286
|
messageKey: Key,
|
|
285
287
|
/** The agent's own message. */
|
|
286
288
|
own: Schema.Boolean,
|
|
@@ -288,6 +290,13 @@ const ContextMessage = Schema.Struct({
|
|
|
288
290
|
senderName: Schema.optionalKey(Schema.NonEmptyString.check(Schema.isMaxLength(256))),
|
|
289
291
|
text: Text,
|
|
290
292
|
timestamp: Timestamp
|
|
293
|
+
};
|
|
294
|
+
/** Published contracts of versions without both `assets` and `readContext` keep this shape. */
|
|
295
|
+
const TextContextMessage = Schema.Struct(contextMessageFields);
|
|
296
|
+
/** A message read back from history; `assets` only where a version declares assets and context. */
|
|
297
|
+
const ContextMessage = Schema.Struct({
|
|
298
|
+
...contextMessageFields,
|
|
299
|
+
assets: Schema.optionalKey(Schema.Array(Asset).check(Schema.isMaxLength(20)))
|
|
291
300
|
});
|
|
292
301
|
/** Decoded originals are limited separately by the host; ordinary command JSON stays bounded. */
|
|
293
302
|
const AssetFile = Schema$1.check(Schema.makeFilter((file) => file.sizeBytes > 0 && file.sizeBytes <= 10485760 && file.contentBase64.length <= 13981016));
|
|
@@ -367,7 +376,7 @@ const installedCommandSchema = (state) => {
|
|
|
367
376
|
})
|
|
368
377
|
]);
|
|
369
378
|
};
|
|
370
|
-
const installedResultSchema = (state) => {
|
|
379
|
+
const installedResultSchema = (state, features) => {
|
|
371
380
|
const operation = {
|
|
372
381
|
extensions: Schema.optionalKey(Extensions),
|
|
373
382
|
operationKey: Key
|
|
@@ -427,7 +436,7 @@ const installedResultSchema = (state) => {
|
|
|
427
436
|
Schema.Struct({
|
|
428
437
|
kind: Schema.Literal("read_context"),
|
|
429
438
|
...operation,
|
|
430
|
-
messages: Schema.Array(ContextMessage).check(Schema.isMaxLength(200))
|
|
439
|
+
messages: Schema.Array(features === void 0 || features.assets && features.readContext === true ? ContextMessage : TextContextMessage).check(Schema.isMaxLength(200))
|
|
431
440
|
})
|
|
432
441
|
]);
|
|
433
442
|
};
|
|
@@ -448,7 +457,8 @@ const readAssetResult = Schema.Struct({
|
|
|
448
457
|
operationKey: Key
|
|
449
458
|
});
|
|
450
459
|
const commandSchema = (state) => Schema.Union([installedCommandSchema(state), readAssetCommand(state)]);
|
|
451
|
-
|
|
460
|
+
/** Pass a version's features to check its results against its own contract. */
|
|
461
|
+
const resultSchema = (state, features) => Schema.Union([installedResultSchema(state, features), readAssetResult]);
|
|
452
462
|
/** Maximum UTF-8 bytes in an ordinary Channel command or result, including its JSON envelope. */
|
|
453
463
|
const resultByteLimit = 2097152;
|
|
454
464
|
/** Keep the newest context messages within the checked result budget, oldest first. */
|
|
@@ -493,7 +503,7 @@ const projectContract = (definition, project = (schema) => Schema.toJsonSchemaDo
|
|
|
493
503
|
extensionsSchemaJson: Object.fromEntries(Object.entries(definition.extensions ?? {}).map(([key, schema]) => [key, project(schema)])),
|
|
494
504
|
featuresJson: definition.features,
|
|
495
505
|
operationInputSchemaJson: project(commandSchema(definition.state)),
|
|
496
|
-
operationOutputSchemaJson: project(resultSchema(definition.state)),
|
|
506
|
+
operationOutputSchemaJson: project(resultSchema(definition.state, definition.features)),
|
|
497
507
|
requiredChecks: definition.requiredChecks,
|
|
498
508
|
stateSchemaJson: project(definition.state)
|
|
499
509
|
}, { onExcessProperty: "error" });
|
package/dist/AgentChannel.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AgentChannel.js","names":["AuthMethod.isAuthMethod"],"sources":["../src/AgentChannel.ts"],"sourcesContent":["/** Provider-neutral external Agent Channel contracts. @since 0.0.0 */\nimport type { Context, Effect, Pipeable, SchemaAST } from \"effect\";\nimport { Match, Predicate, Schema } from \"effect\";\n\nimport * as AuthMethod from \"./AuthMethod.ts\";\nimport { validateIdentifier } from \"./internal/identifier.ts\";\nimport { PipeableProto } from \"./internal/proto.ts\";\nimport * as ToolFile from \"./ToolFile.ts\";\n\nexport const TypeId = \"@dual-os/sdk/AgentChannel\" as const;\nexport type TypeId = typeof TypeId;\n\n/** Keys are opaque and installation-scoped. Never parse them into product identities. */\nexport const Key = Schema.NonEmptyString.check(\n Schema.isMaxLength(512),\n Schema.isPattern(/^[^\\p{Cc}]+$/u),\n);\n/** What a destination can show. Every channel shows `present_outcome`. */\nexport const OperationKind = Schema.Literals([\n \"present_outcome\",\n \"create_message\",\n \"update_message\",\n \"delete_message\",\n \"set_reaction\",\n \"set_activity\",\n \"render_plan\",\n]);\nexport type OperationKind = typeof OperationKind.Type;\nexport const Features = Schema.Struct({\n assets: Schema.Boolean,\n /** Whether replaying one durable delivery key is safe at the provider boundary. */\n deliveryMode: Schema.Literals([\"idempotent\", \"at-most-once\"]),\n deliveryState: Schema.Boolean,\n directText: Schema.Literal(true),\n groups: Schema.Boolean,\n /** Maximum Unicode code points per physical text message, including server-added prefixes. */\n maxTextLength: Schema.optionalKey(Schema.Int.check(Schema.isGreaterThan(0))),\n mentions: Schema.Boolean,\n /** Every definition declares operations; retired catalog contracts still decode without them. */\n operations: Schema.optionalKey(Schema.Array(OperationKind)),\n /** Whether `read_context` returns the conversation's earlier messages. */\n readContext: Schema.optionalKey(Schema.Boolean),\n replies: Schema.Boolean,\n /** Maximum age of the original responding input before preparation and delivery. */\n responseWindowMs: Schema.optionalKey(Schema.Int.check(Schema.isGreaterThan(0))),\n threads: Schema.Boolean,\n});\nexport type Features = typeof Features.Type;\n\nconst HttpUrl = Schema.String.check(\n Schema.isMaxLength(8192),\n Schema.makeFilter(value => {\n const url = URL.parse(value);\n return (\n url !== null &&\n (url.protocol === \"https:\" || url.protocol === \"http:\") &&\n url.username === \"\" &&\n url.password === \"\"\n );\n }),\n);\nconst Text = Schema.String.check(Schema.isMaxLength(65_536));\nconst ExtensionKey = Schema.String.check(\n Schema.isPattern(/^[a-z0-9]+(?:-[a-z0-9]+)*\\/[a-z0-9]+(?:-[a-z0-9]+)*$/),\n);\nconst Extensions = Schema.Record(Schema.String, Schema.Json).check(\n Schema.makeFilter(values => Object.keys(values).every(Schema.is(ExtensionKey))),\n);\nexport const Destination = Schema.Struct({\n conversationKey: Key,\n kind: Schema.Literals([\"direct\", \"group\"]),\n threadKey: Schema.optionalKey(Key),\n});\nexport type Destination = typeof Destination.Type;\nexport const Asset = Schema.Struct({\n assetKey: Key,\n mediaType: Schema.NonEmptyString.check(Schema.isMaxLength(256)),\n url: HttpUrl,\n});\nexport const Content = Schema.Struct({\n assets: Schema.optionalKey(Schema.Array(Asset).check(Schema.isMaxLength(20))),\n mentions: Schema.optionalKey(Schema.Array(Key).check(Schema.isMaxLength(100))),\n replyToMessageKey: Schema.optionalKey(Key),\n text: Text,\n}).check(\n Schema.makeFilter(content => content.text.length > 0 || (content.assets?.length ?? 0) > 0),\n);\nexport type Content = typeof Content.Type;\n\n/** The body is the unmodified UTF-8 provider body, before JSON parsing/signature verification. */\nexport const Request = Schema.Struct({\n body: Schema.String.check(\n Schema.isMaxLength(1_048_576),\n Schema.makeFilter(body => new TextEncoder().encode(body).byteLength <= 1_048_576),\n ),\n headers: Schema.Record(\n Schema.NonEmptyString.check(Schema.isMaxLength(256)),\n Schema.String.check(Schema.isMaxLength(8192)),\n ),\n method: Schema.Literals([\"GET\", \"POST\", \"PUT\", \"PATCH\", \"DELETE\"]),\n url: HttpUrl,\n});\nexport type Request = typeof Request.Type;\nconst ResponseHeaders = Schema.Record(\n Schema.NonEmptyString.check(Schema.isMaxLength(256), Schema.isPattern(/^[a-z0-9-]+$/)),\n Schema.String.check(Schema.isMaxLength(8192)),\n).check(\n Schema.makeFilter(headers =>\n Object.keys(headers).every(name => name === \"content-type\" || name === \"cache-control\"),\n ),\n);\n/**\n * Bounded provider-required webhook response, returned only after request verification. A 204 or\n * 205 response has an empty body.\n */\nexport const WebhookResponse = Schema.Struct({\n body: Schema.String.check(\n Schema.isMaxLength(65_536),\n Schema.makeFilter(body => new TextEncoder().encode(body).byteLength <= 65_536),\n ),\n headers: Schema.optionalKey(ResponseHeaders),\n status: Schema.Int.check(Schema.isBetween({ maximum: 299, minimum: 200 })),\n}).check(\n Schema.makeFilter(\n response => (response.status !== 204 && response.status !== 205) || response.body === \"\",\n ),\n);\nexport type WebhookResponse = typeof WebhookResponse.Type;\nexport const Timestamp = Schema.String.check(\n Schema.isMaxLength(64),\n Schema.isPattern(/^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(?:\\.\\d+)?(?:Z|[+-]\\d{2}:\\d{2})$/),\n Schema.makeFilter(value => {\n const year = Number(value.slice(0, 4));\n const month = Number(value.slice(5, 7));\n const day = Number(value.slice(8, 10));\n const leap = year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0);\n const days = month === 2 ? (leap ? 29 : 28) : [4, 6, 9, 11].includes(month) ? 30 : 31;\n return (\n month >= 1 &&\n month <= 12 &&\n day >= 1 &&\n day <= days &&\n Number(value.slice(11, 13)) < 24 &&\n Number(value.slice(14, 16)) < 60 &&\n Number(value.slice(17, 19)) < 60 &&\n Schema.decodeUnknownExit(Schema.DateTimeUtcFromString)(value)._tag === \"Success\"\n );\n }),\n);\nexport const VerifiedIdentity = Schema.Struct({ conversation: Destination, senderKey: Key });\nexport type VerifiedIdentity = typeof VerifiedIdentity.Type;\nexport const AccessOutcome = Schema.Struct({ decision: Schema.Literals([\"allow\", \"deny\"]) });\nexport type AccessOutcome = typeof AccessOutcome.Type;\nexport const Verification = Schema.Struct({ verified: Schema.Literal(true) });\nexport type Verification = typeof Verification.Type;\nexport const Exposure = Schema.Literals([\"webhook\", \"host\"]);\nexport const RequiredChecks = Schema.Tuple([Schema.Literal(\"access\")]);\nexport const Message = Schema.Struct({\n content: Content,\n conversation: Destination,\n eventKey: Key,\n extensions: Schema.optionalKey(Extensions),\n kind: Schema.Literal(\"message\"),\n messageKey: Key,\n respond: Schema.Boolean,\n senderKey: Key,\n timestamp: Timestamp,\n});\nexport const DeliveryUpdate = Schema.Struct({\n deliveryKey: Key,\n deliveryUpdateKey: Key,\n eventKey: Key,\n extensions: Schema.optionalKey(Extensions),\n kind: Schema.Literal(\"delivery_update\"),\n providerDeliveryKey: Key,\n sequence: Schema.Natural,\n status: Schema.Literals([\"succeeded\", \"failed\"]),\n timestamp: Timestamp,\n});\n/** Provider-confirmed own output. No content is accepted or added to conversation history. */\nexport const Echo = Schema.Struct({\n ...VerifiedIdentity.fields,\n eventKey: Key,\n extensions: Schema.optionalKey(Extensions),\n kind: Schema.Literal(\"echo\"),\n messageKey: Key,\n timestamp: Timestamp,\n});\n/** The sender asked the agent to stop working in this conversation. Access applies. */\nexport const Stop = Schema.Struct({\n ...VerifiedIdentity.fields,\n eventKey: Key,\n extensions: Schema.optionalKey(Extensions),\n kind: Schema.Literal(\"stop\"),\n timestamp: Timestamp,\n});\nexport const Event = Schema.Union([Message, Echo, DeliveryUpdate, Stop]);\nexport type Event = typeof Event.Type;\n\n/** The reactions every provider can show. Each provider maps them to its own emoji. */\nexport const Reaction = Schema.Literals([\n \"thumbs_up\",\n \"thumbs_down\",\n \"laugh\",\n \"confused\",\n \"heart\",\n \"hooray\",\n \"rocket\",\n \"eyes\",\n]);\nexport type Reaction = typeof Reaction.Type;\nconst ShortText = Schema.NonEmptyString.check(Schema.isMaxLength(200));\nexport const PlanItem = Schema.Struct({\n itemKey: Key,\n note: Schema.optionalKey(Schema.NonEmptyString.check(Schema.isMaxLength(2000))),\n state: Schema.Literals([\"pending\", \"in_progress\", \"completed\", \"failed\"]),\n title: Schema.NonEmptyString.check(Schema.isMaxLength(256)),\n});\n/** A whole task list, always sent complete. Item keys are unique and stable across revisions. */\nexport const Plan = Schema.Struct({\n items: Schema.Array(PlanItem).check(\n Schema.isMaxLength(50),\n Schema.makeFilter(items => new Set(items.map(item => item.itemKey)).size === items.length),\n ),\n title: Schema.optionalKey(Schema.NonEmptyString.check(Schema.isMaxLength(256))),\n});\nexport type Plan = typeof Plan.Type;\n/**\n * One piece of output. A `reference` is the `providerDeliveryKey` the provider returned for\n * the message or plan it made; only that provider reads it.\n */\nexport const Operation = Schema.Union([\n /**\n * End the turn. `awaiting_input` ends it with a question, optionally with choices. The\n * provider clears any activity it shows. Earlier parts of a long text arrive as\n * `create_message` operations.\n */\n Schema.Struct({\n kind: Schema.Literal(\"present_outcome\"),\n options: Schema.optionalKey(Schema.Array(ShortText).check(Schema.isMaxLength(10))),\n outcome: Schema.Literals([\"completed\", \"failed\", \"awaiting_input\"]),\n text: Text,\n }).check(\n Schema.makeFilter(\n operation => operation.options === undefined || operation.outcome === \"awaiting_input\",\n ),\n ),\n Schema.Struct({\n kind: Schema.Literal(\"create_message\"),\n messageKey: Key,\n text: Text.check(Schema.isMinLength(1)),\n }),\n Schema.Struct({\n kind: Schema.Literal(\"update_message\"),\n messageKey: Key,\n reference: Key,\n text: Text.check(Schema.isMinLength(1)),\n }),\n Schema.Struct({ kind: Schema.Literal(\"delete_message\"), messageKey: Key, reference: Key }),\n /** Make the agent's reaction present (`active`) or absent. Desired state: repeating is safe. */\n Schema.Struct({\n active: Schema.Boolean,\n kind: Schema.Literal(\"set_reaction\"),\n reaction: Reaction,\n target: Schema.Union([\n /** The message that started the turn: `activationMessageKey` of the command. */\n Schema.Struct({ kind: Schema.Literal(\"activation\") }),\n Schema.Struct({ kind: Schema.Literal(\"message\"), reference: Key }),\n ]),\n }),\n /** What the agent is doing now, such as a typing indicator or a status line. Latest wins. */\n Schema.Struct({\n activity: Schema.Union([\n Schema.Struct({ kind: Schema.Literal(\"working\"), text: Schema.optionalKey(ShortText) }),\n Schema.Struct({ kind: Schema.Literal(\"idle\") }),\n ]),\n kind: Schema.Literal(\"set_activity\"),\n }),\n /** Show this revision of the plan, replacing the one at `reference` when there is one. */\n Schema.Struct({\n kind: Schema.Literal(\"render_plan\"),\n plan: Plan,\n reference: Schema.optionalKey(Key),\n revision: Schema.Int.check(Schema.isGreaterThan(0)),\n }),\n]);\nexport type Operation = typeof Operation.Type;\n/** A message read back from the provider's conversation history. */\nexport const ContextMessage = Schema.Struct({\n messageKey: Key,\n /** The agent's own message. */\n own: Schema.Boolean,\n senderKey: Key,\n senderName: Schema.optionalKey(Schema.NonEmptyString.check(Schema.isMaxLength(256))),\n text: Text,\n timestamp: Timestamp,\n});\nexport type ContextMessage = typeof ContextMessage.Type;\n/** Decoded originals are limited separately by the host; ordinary command JSON stays bounded. */\nexport const AssetFile = ToolFile.Schema.check(\n Schema.makeFilter(\n file =>\n file.sizeBytes > 0 && file.sizeBytes <= 10_485_760 && file.contentBase64.length <= 13_981_016,\n ),\n);\n\n/** Closed error vocabulary: provider messages, payloads, and causes never cross this seam. */\nexport const FailureCode = Schema.Literals([\n \"rejected\",\n \"unauthorized\",\n \"rate_limited\",\n \"unavailable\",\n \"unknown_completion\",\n /** The provider definitely refused this send because its delivery window was closed. */\n \"window_closed\",\n]);\nexport class HandlerError extends Schema.TaggedError<HandlerError>()(\"AgentChannelHandlerError\", {\n code: FailureCode,\n}) {}\nexport const ErrorCode = Schema.Literals([\n \"invalid_definition\",\n \"not_found\",\n \"invalid_input\",\n \"invalid_auth\",\n \"unsupported_feature\",\n \"invalid_result\",\n \"handler_unavailable\",\n \"provider_failure\",\n]);\nexport class ChannelError extends Schema.TaggedError<ChannelError>()(\"AgentChannelError\", {\n code: ErrorCode,\n providerCode: Schema.optionalKey(FailureCode),\n}) {\n override get message(): string {\n return `Agent Channel ${this.code}`;\n }\n}\n\nconst installedCommandSchema = <State extends Schema.Top>(state: State) => {\n const operation = { extensions: Schema.optionalKey(Extensions), operationKey: Key };\n const installed = { ...operation, installationKey: Key, state };\n return Schema.Union([\n Schema.Struct({\n kind: Schema.Literal(\"activate\"),\n ...operation,\n ingressUrl: HttpUrl,\n state: Schema.optionalKey(state),\n }),\n Schema.Struct({ kind: Schema.Literal(\"deactivate\"), ...installed }),\n Schema.Struct({ kind: Schema.Literal(\"receive\"), ...installed, request: Request }),\n Schema.Struct({\n kind: Schema.Literal(\"deliver\"),\n ...installed,\n /** The provider message that started the turn, when the host knows it. */\n activationMessageKey: Schema.optionalKey(Key),\n deliveryKey: Key,\n destination: Destination,\n operation: Operation,\n /** Original responding input timestamp; retries must preserve this reference. */\n responseToTimestamp: Schema.optionalKey(Timestamp),\n }),\n /** The conversation's latest messages, oldest first, at most `limit`. */\n Schema.Struct({\n kind: Schema.Literal(\"read_context\"),\n ...installed,\n destination: Destination,\n limit: Schema.Int.check(Schema.isBetween({ maximum: 200, minimum: 1 })),\n }),\n ]);\n};\n\nconst installedResultSchema = <State extends Schema.Top>(state: State) => {\n const operation = { extensions: Schema.optionalKey(Extensions), operationKey: Key };\n return Schema.Union([\n Schema.Struct({\n kind: Schema.Literal(\"activate\"),\n ...operation,\n installationKey: Key,\n state,\n /** Durable read-only provider state that the host must persist before retrying activation. */\n checkpoint: Schema.optionalKey(Schema.Literal(true)),\n /** The host must observe a verified webhook handshake before cutover. */\n verification: Schema.optionalKey(Schema.Literal(\"ingress\")),\n }),\n Schema.Struct({ kind: Schema.Literal(\"deactivate\"), ...operation }),\n Schema.Struct({\n kind: Schema.Literal(\"receive\"),\n ...operation,\n verified: Schema.Literal(true),\n deniedEventKeys: Schema.optionalKey(Schema.Array(Key).check(Schema.isMaxLength(100))),\n events: Schema.Array(Event).check(Schema.isMaxLength(100)),\n response: Schema.optionalKey(WebhookResponse),\n /** A provider-native setup challenge or ping proved the configured ingress. */\n activationProof: Schema.optionalKey(Schema.Literal(\"verified\")),\n }),\n Schema.Struct({\n kind: Schema.Literal(\"deliver\"),\n ...operation,\n deliveryKey: Key,\n status: Schema.Literal(\"succeeded\"),\n providerDeliveryKey: Key,\n }),\n Schema.Struct({\n kind: Schema.Literal(\"deliver\"),\n ...operation,\n deliveryKey: Key,\n status: Schema.Literal(\"pending\"),\n providerDeliveryKey: Key,\n }),\n Schema.Struct({\n kind: Schema.Literal(\"deliver\"),\n ...operation,\n deliveryKey: Key,\n status: Schema.Literal(\"failed\"),\n code: Schema.Literals([\n \"rejected\",\n \"unauthorized\",\n \"rate_limited\",\n \"unavailable\",\n \"window_closed\",\n ]),\n }),\n Schema.Struct({\n kind: Schema.Literal(\"read_context\"),\n ...operation,\n messages: Schema.Array(ContextMessage).check(Schema.isMaxLength(200)),\n }),\n ]);\n};\nconst readAssetCommand = <State extends Schema.Top>(state: State) =>\n Schema.Struct({\n asset: Asset,\n extensions: Schema.optionalKey(Extensions),\n identity: VerifiedIdentity,\n installationKey: Key,\n kind: Schema.Literal(\"read_asset\"),\n operationKey: Key,\n state,\n });\nconst readAssetResult = Schema.Struct({\n assetKey: Key,\n extensions: Schema.optionalKey(Extensions),\n file: AssetFile,\n kind: Schema.Literal(\"read_asset\"),\n operationKey: Key,\n});\nexport const commandSchema = <State extends Schema.Top>(state: State) =>\n Schema.Union([installedCommandSchema(state), readAssetCommand(state)]);\nexport const resultSchema = <State extends Schema.Top>(state: State) =>\n Schema.Union([installedResultSchema(state), readAssetResult]);\nexport type Command<State extends Schema.Top = Schema.Unknown> = ReturnType<\n typeof commandSchema<State>\n>[\"Type\"];\nexport type Result<State extends Schema.Top = Schema.Unknown> = ReturnType<\n typeof resultSchema<State>\n>[\"Type\"];\n/** Maximum UTF-8 bytes in an ordinary Channel command or result, including its JSON envelope. */\nexport const resultByteLimit = 2_097_152;\n/** Keep the newest context messages within the checked result budget, oldest first. */\nexport function contextResult(\n operationKey: string,\n context: readonly ContextMessage[],\n): Extract<Result, { readonly kind: \"read_context\" }> {\n const messages: ContextMessage[] = [];\n const result = { kind: \"read_context\" as const, messages, operationKey };\n const encoder = new TextEncoder();\n let bytes = encoder.encode(JSON.stringify(result)).byteLength;\n for (let index = context.length - 1; index >= 0; index--) {\n const message = context[index];\n if (message === undefined) continue;\n const size = encoder.encode(JSON.stringify(message)).byteLength + 1;\n if (bytes + size > resultByteLimit) break;\n bytes += size;\n messages.unshift(message);\n }\n return result;\n}\n/** Encoded, JSON-safe runtime result suitable for host persistence. */\nexport const CheckedResult = resultSchema(Schema.Json);\nexport type CheckedResult = typeof CheckedResult.Type;\n\n/** Immutable catalog projection. Live schemas remain the execution validators. */\nexport const Contract = Schema.Struct({\n definitionSettingsSchemaJson: Schema.Json,\n deploymentSettingsSchemaJson: Schema.Json,\n exposure: Exposure,\n extensionsSchemaJson: Schema.Record(Schema.String, Schema.Json),\n featuresJson: Features.check(\n Schema.makeFilter(features => (features.operations ?? []).includes(\"present_outcome\")),\n ),\n operationInputSchemaJson: Schema.Json,\n operationOutputSchemaJson: Schema.Json,\n requiredChecks: RequiredChecks,\n stateSchemaJson: Schema.Json,\n});\nexport type Contract = typeof Contract.Type;\n\nexport interface Definition<\n Settings extends Schema.Top = Schema.Top,\n Mappings extends Schema.Top = Schema.Top,\n State extends Schema.Top = Schema.Top,\n Methods extends readonly AuthMethod.Any[] = readonly AuthMethod.Any[],\n> {\n readonly definitionSettings: Settings;\n readonly deploymentSettings: Mappings;\n readonly state: State;\n readonly features: Features;\n readonly exposure: typeof Exposure.Type;\n readonly requiredChecks: typeof RequiredChecks.Type;\n /** Explicit subset of the provider's methods; [] means the channel accepts no connection. */\n readonly authMethods: Methods;\n /** Each key is provider/name. Values are checked on every command/result/event. */\n readonly extensions?: Readonly<Record<string, Schema.Top>>;\n}\n/** Project the exact declaration once for SDK discovery and server contract comparison. */\nexport const projectContract = (\n definition: Definition,\n project: (schema: Schema.Top) => unknown = schema =>\n Schema.toJsonSchemaDocument(schema, { onExcessProperty: \"error\" }),\n): Contract =>\n Schema.decodeUnknownSync(Contract)(\n {\n definitionSettingsSchemaJson: project(definition.definitionSettings),\n deploymentSettingsSchemaJson: project(definition.deploymentSettings),\n exposure: definition.exposure,\n extensionsSchemaJson: Object.fromEntries(\n Object.entries(definition.extensions ?? {}).map(([key, schema]) => [key, project(schema)]),\n ),\n featuresJson: definition.features,\n operationInputSchemaJson: project(commandSchema(definition.state)),\n operationOutputSchemaJson: project(resultSchema(definition.state)),\n requiredChecks: definition.requiredChecks,\n stateSchemaJson: project(definition.state),\n },\n { onExcessProperty: \"error\" },\n );\nexport interface Any extends Pipeable.Pipeable {\n readonly [TypeId]: TypeId;\n readonly identifier: string;\n readonly name: string | undefined;\n readonly description: string | undefined;\n readonly definition: Definition;\n}\nexport interface AgentChannel<\n out Identifier extends string = string,\n out D extends Definition = Definition,\n> extends Any {\n readonly identifier: Identifier;\n readonly definition: D;\n}\nexport type ResolvedAuth<Methods extends readonly AuthMethod.Any[]> =\n Methods[number] extends infer M\n ? M extends AuthMethod.Any\n ? { readonly methodId: M[\"identifier\"]; readonly value: AuthMethod.Value<M> }\n : never\n : never;\nexport type HandlerContext<D extends Definition> = {\n readonly definitionSettings: D[\"definitionSettings\"][\"Type\"];\n readonly deploymentSettings: D[\"deploymentSettings\"][\"Type\"];\n} & (D[\"authMethods\"] extends readonly []\n ? {}\n : number extends D[\"authMethods\"][\"length\"]\n ? { readonly auth?: ResolvedAuth<D[\"authMethods\"]> }\n : { readonly auth: ResolvedAuth<D[\"authMethods\"]> });\n/** The command a Channel's handler receives. */\nexport type CommandFor<D extends Definition> = Command<D[\"state\"]>;\n/** The result a Channel's handler returns. */\nexport type ResultFor<D extends Definition> = Result<D[\"state\"]>;\nexport interface RuntimeContract<D extends Definition, R = never> {\n readonly verify: (\n request: Request,\n context: HandlerContext<D>,\n ) => Effect.Effect<Verification, HandlerError, R>;\n readonly checkAccess: (\n identity: VerifiedIdentity,\n context: HandlerContext<D>,\n ) => Effect.Effect<AccessOutcome, HandlerError, R>;\n readonly execute: (\n command: CommandFor<D>,\n context: HandlerContext<D>,\n ) => Effect.Effect<ResultFor<D>, HandlerError, R>;\n}\n/** Erased service representation. Input and output are checked by AgentChannelRuntime. */\nexport interface Handler<Id extends string = string> {\n readonly channelId: Id;\n readonly context: Context.Context<never>;\n readonly runtime: {\n readonly verify: (\n request: unknown,\n context: unknown,\n ) => Effect.Effect<unknown, unknown, unknown>;\n readonly checkAccess: (\n identity: unknown,\n context: unknown,\n ) => Effect.Effect<unknown, unknown, unknown>;\n readonly execute: (\n command: unknown,\n context: unknown,\n ) => Effect.Effect<unknown, unknown, unknown>;\n };\n}\nexport const handlerKey = (channelId: string): string =>\n `@dual-os/sdk/AgentChannel/Handler/${channelId}`;\n\nconst SchemaDefinition = Schema.declare(Schema.isSchema);\n// Fail closed on holes such as Unknown nested inside an otherwise typed state schema.\nconst checkSchema = (schema: Schema.Top, allowOpaque = false): void => {\n const seen = new Set<SchemaAST.AST>();\n const visit = (ast: SchemaAST.AST): void => {\n if (seen.has(ast)) return;\n seen.add(ast);\n if (\n ast.annotations?.[\"parseOptions\"] !== undefined ||\n (ast.checks?.some(check => check.annotations?.[\"parseOptions\"] !== undefined) ?? false)\n ) {\n throw new ChannelError({ code: \"invalid_definition\" });\n }\n ast.encoding?.forEach(link => {\n visit(link.to);\n });\n Match.value(ast).pipe(\n Match.tag(\"Unknown\", \"Any\", \"ObjectKeyword\", () => {\n throw new ChannelError({ code: \"invalid_definition\" });\n }),\n Match.tag(\"Declaration\", declaration => {\n if (!allowOpaque) throw new ChannelError({ code: \"invalid_definition\" });\n declaration.typeParameters.forEach(visit);\n }),\n Match.tag(\"Objects\", objects => {\n objects.propertySignatures.forEach(property => visit(property.type));\n objects.indexSignatures.forEach(index => {\n // Filtered keys may disappear silently; a channel contract must retain them.\n if (\n index.parameter._tag !== \"String\" ||\n index.parameter.checks !== undefined ||\n index.parameter.encoding !== undefined\n ) {\n throw new ChannelError({ code: \"invalid_definition\" });\n }\n visit(index.parameter);\n visit(index.type);\n });\n }),\n Match.tag(\"Arrays\", arrays => {\n arrays.elements.forEach(visit);\n arrays.rest.forEach(visit);\n }),\n Match.tag(\"Union\", union => {\n union.types.forEach(visit);\n }),\n Match.tag(\"Suspend\", suspend => {\n visit(suspend.thunk());\n }),\n Match.orElse(() => undefined),\n );\n };\n visit(schema.ast);\n};\nconst DefinitionSchema = Schema.Struct({\n authMethods: Schema.Array(Schema.declare(AuthMethod.isAuthMethod)),\n definitionSettings: SchemaDefinition,\n deploymentSettings: SchemaDefinition,\n exposure: Exposure,\n extensions: Schema.optionalKey(\n Schema.Record(Schema.String, SchemaDefinition).check(\n Schema.makeFilter(values => Object.keys(values).every(Schema.is(ExtensionKey))),\n ),\n ),\n features: Features,\n requiredChecks: RequiredChecks,\n state: SchemaDefinition,\n}).check(\n Schema.makeFilter(({ features }) => {\n const operations = features.operations ?? [];\n return (\n operations.includes(\"present_outcome\") &&\n new Set(operations).size === operations.length &&\n // A long text arrives as messages before its outcome.\n (features.maxTextLength === undefined || operations.includes(\"create_message\"))\n );\n }),\n);\n\n/** Validate declarations at registration as well as at builder time. */\nexport const validateDefinition = (\n definition: Definition,\n providerId?: string,\n methods?: readonly AuthMethod.Any[],\n): void => {\n try {\n Schema.decodeUnknownSync(DefinitionSchema)(definition, { onExcessProperty: \"error\" });\n for (const schema of [\n definition.definitionSettings,\n definition.deploymentSettings,\n definition.state,\n ...Object.values(definition.extensions ?? {}),\n ]) {\n // A JSON projection must exist; it is catalog metadata, never the execution validator.\n checkSchema(schema);\n Schema.toJsonSchemaDocument(schema);\n }\n const seen = new Set<string>();\n for (const method of definition.authMethods) {\n if (seen.has(method.identifier) || (methods !== undefined && !methods.includes(method))) {\n throw new ChannelError({ code: \"invalid_definition\" });\n }\n seen.add(method.identifier);\n Schema.decodeUnknownSync(SchemaDefinition)(method.material);\n Schema.decodeUnknownSync(SchemaDefinition)(method.value);\n for (const schema of [\n method.material,\n method.value,\n ...(method.setup === undefined ? [] : [method.setup]),\n ]) {\n checkSchema(schema, true);\n }\n }\n if (\n providerId !== undefined &&\n Object.keys(definition.extensions ?? {}).some(key => !key.startsWith(`${providerId}/`))\n ) {\n throw new ChannelError({ code: \"invalid_definition\" });\n }\n } catch {\n throw new ChannelError({ code: \"invalid_definition\" });\n }\n};\n\nexport interface ChannelOptions {\n readonly name?: string;\n readonly description?: string;\n}\n\n/** Create a Channel from its contract. */\nexport const make = <const Id extends string, const O extends Definition & ChannelOptions>(\n identifier: Id,\n options: O,\n): AgentChannel<Id, O> => {\n validateIdentifier(\"agent-channel\", identifier);\n const { description, name, ...definition }: Definition & ChannelOptions = options;\n validateDefinition(definition);\n return {\n ...PipeableProto,\n [TypeId]: TypeId,\n definition: Object.freeze({\n ...definition,\n authMethods: Object.freeze([...definition.authMethods]),\n features: Object.freeze({ ...definition.features }),\n requiredChecks: Object.freeze([...definition.requiredChecks]),\n ...(definition.extensions === undefined\n ? {}\n : { extensions: Object.freeze({ ...definition.extensions }) }),\n }),\n description,\n identifier,\n name,\n } as AgentChannel<Id, O>;\n};\nexport const isAgentChannel = (value: unknown): value is Any =>\n Predicate.hasProperty(value, TypeId);\n\nexport * as AgentChannel from \"./AgentChannel.ts\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AASA,MAAa,SAAS;;AAItB,MAAa,MAAM,OAAO,eAAe,MACvC,OAAO,YAAY,GAAG,GACtB,OAAO,UAAU,eAAe,CAClC;;AAEA,MAAa,gBAAgB,OAAO,SAAS;CAC3C;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;AAED,MAAa,WAAW,OAAO,OAAO;CACpC,QAAQ,OAAO;;CAEf,cAAc,OAAO,SAAS,CAAC,cAAc,cAAc,CAAC;CAC5D,eAAe,OAAO;CACtB,YAAY,OAAO,QAAQ,IAAI;CAC/B,QAAQ,OAAO;;CAEf,eAAe,OAAO,YAAY,OAAO,IAAI,MAAM,OAAO,cAAc,CAAC,CAAC,CAAC;CAC3E,UAAU,OAAO;;CAEjB,YAAY,OAAO,YAAY,OAAO,MAAM,aAAa,CAAC;;CAE1D,aAAa,OAAO,YAAY,OAAO,OAAO;CAC9C,SAAS,OAAO;;CAEhB,kBAAkB,OAAO,YAAY,OAAO,IAAI,MAAM,OAAO,cAAc,CAAC,CAAC,CAAC;CAC9E,SAAS,OAAO;AAClB,CAAC;AAGD,MAAM,UAAU,OA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;IACP,GAAI,OAAO,UAAU,KAAA,IAAY,CAAC,IAAI,CAAC,OAAO,KAAK;GACrD,GACE,YAAY,QAAQ,IAAI;EAE5B;EACA,IACE,eAAe,KAAA,KACf,OAAO,KAAK,WAAW,cAAc,CAAC,CAAC,CAAC,CAAC,MAAK,QAAO,CAAC,IAAI,WAAW,GAAG,WAAW,EAAE,CAAC,GAEtF,MAAM,IAAI,aAAa,EAAE,MAAM,qBAAqB,CAAC;CAEzD,QAAQ;EACN,MAAM,IAAI,aAAa,EAAE,MAAM,qBAAqB,CAAC;CACvD;AACF;;AAQA,MAAa,QACX,YACA,YACwB;CACxB,mBAAmB,iBAAiB,UAAU;CAC9C,MAAM,EAAE,aAAa,MAAM,GAAG,eAA4C;CAC1E,mBAAmB,UAAU;CAC7B,OAAO;EACL,GAAG;GACF,SAAS;EACV,YAAY,OAAO,OAAO;GACxB,GAAG;GACH,aAAa,OAAO,OAAO,CAAC,GAAG,WAAW,WAAW,CAAC;GACtD,UAAU,OAAO,OAAO,EAAE,GAAG,WAAW,SAAS,CAAC;GAClD,gBAAgB,OAAO,OAAO,CAAC,GAAG,WAAW,cAAc,CAAC;GAC5D,GAAI,WAAW,eAAe,KAAA,IAC1B,CAAC,IACD,EAAE,YAAY,OAAO,OAAO,EAAE,GAAG,WAAW,WAAW,CAAC,EAAE;EAChE,CAAC;EACD;EACA;EACA;CACF;AACF;AACA,MAAa,kBAAkB,UAC7B,UAAU,YAAY,OAAO,MAAM"}
|
|
1
|
+
{"version":3,"file":"AgentChannel.js","names":["AuthMethod.isAuthMethod"],"sources":["../src/AgentChannel.ts"],"sourcesContent":["/** Provider-neutral external Agent Channel contracts. @since 0.0.0 */\nimport type { Context, Effect, Pipeable, SchemaAST } from \"effect\";\nimport { Match, Predicate, Schema } from \"effect\";\n\nimport * as AuthMethod from \"./AuthMethod.ts\";\nimport { validateIdentifier } from \"./internal/identifier.ts\";\nimport { PipeableProto } from \"./internal/proto.ts\";\nimport * as ToolFile from \"./ToolFile.ts\";\n\nexport const TypeId = \"@dual-os/sdk/AgentChannel\" as const;\nexport type TypeId = typeof TypeId;\n\n/** Keys are opaque and installation-scoped. Never parse them into product identities. */\nexport const Key = Schema.NonEmptyString.check(\n Schema.isMaxLength(512),\n Schema.isPattern(/^[^\\p{Cc}]+$/u),\n);\n/** What a destination can show. Every channel shows `present_outcome`. */\nexport const OperationKind = Schema.Literals([\n \"present_outcome\",\n \"create_message\",\n \"update_message\",\n \"delete_message\",\n \"set_reaction\",\n \"set_activity\",\n \"render_plan\",\n]);\nexport type OperationKind = typeof OperationKind.Type;\nexport const Features = Schema.Struct({\n assets: Schema.Boolean,\n /** Whether replaying one durable delivery key is safe at the provider boundary. */\n deliveryMode: Schema.Literals([\"idempotent\", \"at-most-once\"]),\n deliveryState: Schema.Boolean,\n directText: Schema.Literal(true),\n groups: Schema.Boolean,\n /** Maximum Unicode code points per physical text message, including server-added prefixes. */\n maxTextLength: Schema.optionalKey(Schema.Int.check(Schema.isGreaterThan(0))),\n mentions: Schema.Boolean,\n /**\n * The output operations every destination of this version shows. Every definition declares\n * them; retired catalog contracts that predate them still decode.\n */\n operations: Schema.optionalKey(Schema.Array(OperationKind)),\n /** Whether `read_context` returns the conversation's earlier messages. */\n readContext: Schema.optionalKey(Schema.Boolean),\n replies: Schema.Boolean,\n /** Maximum age of the original responding input before preparation and delivery. */\n responseWindowMs: Schema.optionalKey(Schema.Int.check(Schema.isGreaterThan(0))),\n threads: Schema.Boolean,\n});\nexport type Features = typeof Features.Type;\n\nconst HttpUrl = Schema.String.check(\n Schema.isMaxLength(8192),\n Schema.makeFilter(value => {\n const url = URL.parse(value);\n return (\n url !== null &&\n (url.protocol === \"https:\" || url.protocol === \"http:\") &&\n url.username === \"\" &&\n url.password === \"\"\n );\n }),\n);\nconst Text = Schema.String.check(Schema.isMaxLength(65_536));\nconst ExtensionKey = Schema.String.check(\n Schema.isPattern(/^[a-z0-9]+(?:-[a-z0-9]+)*\\/[a-z0-9]+(?:-[a-z0-9]+)*$/),\n);\nconst Extensions = Schema.Record(Schema.String, Schema.Json).check(\n Schema.makeFilter(values => Object.keys(values).every(Schema.is(ExtensionKey))),\n);\nexport const Destination = Schema.Struct({\n conversationKey: Key,\n kind: Schema.Literals([\"direct\", \"group\"]),\n threadKey: Schema.optionalKey(Key),\n});\nexport type Destination = typeof Destination.Type;\nexport const Asset = Schema.Struct({\n assetKey: Key,\n mediaType: Schema.NonEmptyString.check(Schema.isMaxLength(256)),\n url: HttpUrl,\n});\nexport const Content = Schema.Struct({\n assets: Schema.optionalKey(Schema.Array(Asset).check(Schema.isMaxLength(20))),\n mentions: Schema.optionalKey(Schema.Array(Key).check(Schema.isMaxLength(100))),\n replyToMessageKey: Schema.optionalKey(Key),\n text: Text,\n}).check(\n Schema.makeFilter(content => content.text.length > 0 || (content.assets?.length ?? 0) > 0),\n);\nexport type Content = typeof Content.Type;\n\n/** The body is the unmodified UTF-8 provider body, before JSON parsing/signature verification. */\nexport const Request = Schema.Struct({\n body: Schema.String.check(\n Schema.isMaxLength(1_048_576),\n Schema.makeFilter(body => new TextEncoder().encode(body).byteLength <= 1_048_576),\n ),\n headers: Schema.Record(\n Schema.NonEmptyString.check(Schema.isMaxLength(256)),\n Schema.String.check(Schema.isMaxLength(8192)),\n ),\n method: Schema.Literals([\"GET\", \"POST\", \"PUT\", \"PATCH\", \"DELETE\"]),\n url: HttpUrl,\n});\nexport type Request = typeof Request.Type;\nconst ResponseHeaders = Schema.Record(\n Schema.NonEmptyString.check(Schema.isMaxLength(256), Schema.isPattern(/^[a-z0-9-]+$/)),\n Schema.String.check(Schema.isMaxLength(8192)),\n).check(\n Schema.makeFilter(headers =>\n Object.keys(headers).every(name => name === \"content-type\" || name === \"cache-control\"),\n ),\n);\n/**\n * Bounded provider-required webhook response, returned only after request verification. A 204 or\n * 205 response has an empty body.\n */\nexport const WebhookResponse = Schema.Struct({\n body: Schema.String.check(\n Schema.isMaxLength(65_536),\n Schema.makeFilter(body => new TextEncoder().encode(body).byteLength <= 65_536),\n ),\n headers: Schema.optionalKey(ResponseHeaders),\n status: Schema.Int.check(Schema.isBetween({ maximum: 299, minimum: 200 })),\n}).check(\n Schema.makeFilter(\n response => (response.status !== 204 && response.status !== 205) || response.body === \"\",\n ),\n);\nexport type WebhookResponse = typeof WebhookResponse.Type;\nexport const Timestamp = Schema.String.check(\n Schema.isMaxLength(64),\n Schema.isPattern(/^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(?:\\.\\d+)?(?:Z|[+-]\\d{2}:\\d{2})$/),\n Schema.makeFilter(value => {\n const year = Number(value.slice(0, 4));\n const month = Number(value.slice(5, 7));\n const day = Number(value.slice(8, 10));\n const leap = year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0);\n const days = month === 2 ? (leap ? 29 : 28) : [4, 6, 9, 11].includes(month) ? 30 : 31;\n return (\n month >= 1 &&\n month <= 12 &&\n day >= 1 &&\n day <= days &&\n Number(value.slice(11, 13)) < 24 &&\n Number(value.slice(14, 16)) < 60 &&\n Number(value.slice(17, 19)) < 60 &&\n Schema.decodeUnknownExit(Schema.DateTimeUtcFromString)(value)._tag === \"Success\"\n );\n }),\n);\nexport const VerifiedIdentity = Schema.Struct({ conversation: Destination, senderKey: Key });\nexport type VerifiedIdentity = typeof VerifiedIdentity.Type;\nexport const AccessOutcome = Schema.Struct({ decision: Schema.Literals([\"allow\", \"deny\"]) });\nexport type AccessOutcome = typeof AccessOutcome.Type;\nexport const Verification = Schema.Struct({ verified: Schema.Literal(true) });\nexport type Verification = typeof Verification.Type;\nexport const Exposure = Schema.Literals([\"webhook\", \"host\"]);\nexport const RequiredChecks = Schema.Tuple([Schema.Literal(\"access\")]);\nexport const Message = Schema.Struct({\n content: Content,\n conversation: Destination,\n eventKey: Key,\n extensions: Schema.optionalKey(Extensions),\n kind: Schema.Literal(\"message\"),\n messageKey: Key,\n respond: Schema.Boolean,\n senderKey: Key,\n timestamp: Timestamp,\n});\nexport const DeliveryUpdate = Schema.Struct({\n deliveryKey: Key,\n deliveryUpdateKey: Key,\n eventKey: Key,\n extensions: Schema.optionalKey(Extensions),\n kind: Schema.Literal(\"delivery_update\"),\n providerDeliveryKey: Key,\n sequence: Schema.Natural,\n status: Schema.Literals([\"succeeded\", \"failed\"]),\n timestamp: Timestamp,\n});\n/** Provider-confirmed own output. No content is accepted or added to conversation history. */\nexport const Echo = Schema.Struct({\n ...VerifiedIdentity.fields,\n eventKey: Key,\n extensions: Schema.optionalKey(Extensions),\n kind: Schema.Literal(\"echo\"),\n messageKey: Key,\n timestamp: Timestamp,\n});\n/** The sender asked the agent to stop working in this conversation. Access applies. */\nexport const Stop = Schema.Struct({\n ...VerifiedIdentity.fields,\n eventKey: Key,\n extensions: Schema.optionalKey(Extensions),\n kind: Schema.Literal(\"stop\"),\n timestamp: Timestamp,\n});\nexport const Event = Schema.Union([Message, Echo, DeliveryUpdate, Stop]);\nexport type Event = typeof Event.Type;\n\n/** The reactions every provider can show. Each provider maps them to its own emoji. */\nexport const Reaction = Schema.Literals([\n \"thumbs_up\",\n \"thumbs_down\",\n \"laugh\",\n \"confused\",\n \"heart\",\n \"hooray\",\n \"rocket\",\n \"eyes\",\n]);\nexport type Reaction = typeof Reaction.Type;\nconst ShortText = Schema.NonEmptyString.check(Schema.isMaxLength(200));\nexport const PlanItem = Schema.Struct({\n itemKey: Key,\n note: Schema.optionalKey(Schema.NonEmptyString.check(Schema.isMaxLength(2000))),\n state: Schema.Literals([\"pending\", \"in_progress\", \"completed\", \"failed\"]),\n title: Schema.NonEmptyString.check(Schema.isMaxLength(256)),\n});\n/** A whole task list, always sent complete. Item keys are unique and stable across revisions. */\nexport const Plan = Schema.Struct({\n items: Schema.Array(PlanItem).check(\n Schema.isMaxLength(50),\n Schema.makeFilter(items => new Set(items.map(item => item.itemKey)).size === items.length),\n ),\n title: Schema.optionalKey(Schema.NonEmptyString.check(Schema.isMaxLength(256))),\n});\nexport type Plan = typeof Plan.Type;\n/**\n * One piece of output. A `reference` is the `providerDeliveryKey` the provider returned for\n * the message or plan it made; only that provider reads it.\n */\nexport const Operation = Schema.Union([\n /**\n * End the turn. `awaiting_input` ends it with a question, optionally with choices. The\n * provider clears any activity it shows. Earlier parts of a long text arrive as\n * `create_message` operations.\n */\n Schema.Struct({\n kind: Schema.Literal(\"present_outcome\"),\n options: Schema.optionalKey(Schema.Array(ShortText).check(Schema.isMaxLength(10))),\n outcome: Schema.Literals([\"completed\", \"failed\", \"awaiting_input\"]),\n text: Text,\n }).check(\n Schema.makeFilter(\n operation => operation.options === undefined || operation.outcome === \"awaiting_input\",\n ),\n ),\n Schema.Struct({\n kind: Schema.Literal(\"create_message\"),\n messageKey: Key,\n text: Text.check(Schema.isMinLength(1)),\n }),\n Schema.Struct({\n kind: Schema.Literal(\"update_message\"),\n messageKey: Key,\n reference: Key,\n text: Text.check(Schema.isMinLength(1)),\n }),\n Schema.Struct({ kind: Schema.Literal(\"delete_message\"), messageKey: Key, reference: Key }),\n /** Make the agent's reaction present (`active`) or absent. Desired state: repeating is safe. */\n Schema.Struct({\n active: Schema.Boolean,\n kind: Schema.Literal(\"set_reaction\"),\n reaction: Reaction,\n target: Schema.Union([\n /** The message that started the turn: `activationMessageKey` of the command. */\n Schema.Struct({ kind: Schema.Literal(\"activation\") }),\n Schema.Struct({ kind: Schema.Literal(\"message\"), reference: Key }),\n ]),\n }),\n /** What the agent is doing now, such as a typing indicator or a status line. Latest wins. */\n Schema.Struct({\n activity: Schema.Union([\n Schema.Struct({ kind: Schema.Literal(\"working\"), text: Schema.optionalKey(ShortText) }),\n Schema.Struct({ kind: Schema.Literal(\"idle\") }),\n ]),\n kind: Schema.Literal(\"set_activity\"),\n }),\n /** Show this revision of the plan, replacing the one at `reference` when there is one. */\n Schema.Struct({\n kind: Schema.Literal(\"render_plan\"),\n plan: Plan,\n reference: Schema.optionalKey(Key),\n revision: Schema.Int.check(Schema.isGreaterThan(0)),\n }),\n]);\nexport type Operation = typeof Operation.Type;\nconst contextMessageFields = {\n messageKey: Key,\n /** The agent's own message. */\n own: Schema.Boolean,\n senderKey: Key,\n senderName: Schema.optionalKey(Schema.NonEmptyString.check(Schema.isMaxLength(256))),\n text: Text,\n timestamp: Timestamp,\n};\n/** Published contracts of versions without both `assets` and `readContext` keep this shape. */\nconst TextContextMessage = Schema.Struct(contextMessageFields);\n/** A message read back from history; `assets` only where a version declares assets and context. */\nexport const ContextMessage = Schema.Struct({\n ...contextMessageFields,\n assets: Schema.optionalKey(Schema.Array(Asset).check(Schema.isMaxLength(20))),\n});\nexport type ContextMessage = typeof ContextMessage.Type;\n\n/** Decoded originals are limited separately by the host; ordinary command JSON stays bounded. */\nexport const AssetFile = ToolFile.Schema.check(\n Schema.makeFilter(\n file =>\n file.sizeBytes > 0 && file.sizeBytes <= 10_485_760 && file.contentBase64.length <= 13_981_016,\n ),\n);\n\n/** Closed error vocabulary: provider messages, payloads, and causes never cross this seam. */\nexport const FailureCode = Schema.Literals([\n \"rejected\",\n \"unauthorized\",\n \"rate_limited\",\n \"unavailable\",\n \"unknown_completion\",\n /** The provider definitely refused this send because its delivery window was closed. */\n \"window_closed\",\n]);\nexport class HandlerError extends Schema.TaggedError<HandlerError>()(\"AgentChannelHandlerError\", {\n code: FailureCode,\n}) {}\nexport const ErrorCode = Schema.Literals([\n \"invalid_definition\",\n \"not_found\",\n \"invalid_input\",\n \"invalid_auth\",\n \"unsupported_feature\",\n \"invalid_result\",\n \"handler_unavailable\",\n \"provider_failure\",\n]);\nexport class ChannelError extends Schema.TaggedError<ChannelError>()(\"AgentChannelError\", {\n code: ErrorCode,\n providerCode: Schema.optionalKey(FailureCode),\n}) {\n override get message(): string {\n return `Agent Channel ${this.code}`;\n }\n}\n\nconst installedCommandSchema = <State extends Schema.Top>(state: State) => {\n const operation = { extensions: Schema.optionalKey(Extensions), operationKey: Key };\n const installed = { ...operation, installationKey: Key, state };\n return Schema.Union([\n Schema.Struct({\n kind: Schema.Literal(\"activate\"),\n ...operation,\n ingressUrl: HttpUrl,\n state: Schema.optionalKey(state),\n }),\n Schema.Struct({ kind: Schema.Literal(\"deactivate\"), ...installed }),\n Schema.Struct({ kind: Schema.Literal(\"receive\"), ...installed, request: Request }),\n Schema.Struct({\n kind: Schema.Literal(\"deliver\"),\n ...installed,\n /** The provider message that started the turn, when the host knows it. */\n activationMessageKey: Schema.optionalKey(Key),\n deliveryKey: Key,\n destination: Destination,\n operation: Operation,\n /** Original responding input timestamp; retries must preserve this reference. */\n responseToTimestamp: Schema.optionalKey(Timestamp),\n }),\n /** The conversation's latest messages, oldest first, at most `limit`. */\n Schema.Struct({\n kind: Schema.Literal(\"read_context\"),\n ...installed,\n destination: Destination,\n limit: Schema.Int.check(Schema.isBetween({ maximum: 200, minimum: 1 })),\n }),\n ]);\n};\n\nconst installedResultSchema = <State extends Schema.Top>(state: State, features?: Features) => {\n const operation = { extensions: Schema.optionalKey(Extensions), operationKey: Key };\n return Schema.Union([\n Schema.Struct({\n kind: Schema.Literal(\"activate\"),\n ...operation,\n installationKey: Key,\n state,\n /** Durable read-only provider state that the host must persist before retrying activation. */\n checkpoint: Schema.optionalKey(Schema.Literal(true)),\n /** The host must observe a verified webhook handshake before cutover. */\n verification: Schema.optionalKey(Schema.Literal(\"ingress\")),\n }),\n Schema.Struct({ kind: Schema.Literal(\"deactivate\"), ...operation }),\n Schema.Struct({\n kind: Schema.Literal(\"receive\"),\n ...operation,\n verified: Schema.Literal(true),\n deniedEventKeys: Schema.optionalKey(Schema.Array(Key).check(Schema.isMaxLength(100))),\n events: Schema.Array(Event).check(Schema.isMaxLength(100)),\n response: Schema.optionalKey(WebhookResponse),\n /** A provider-native setup challenge or ping proved the configured ingress. */\n activationProof: Schema.optionalKey(Schema.Literal(\"verified\")),\n }),\n Schema.Struct({\n kind: Schema.Literal(\"deliver\"),\n ...operation,\n deliveryKey: Key,\n status: Schema.Literal(\"succeeded\"),\n providerDeliveryKey: Key,\n }),\n Schema.Struct({\n kind: Schema.Literal(\"deliver\"),\n ...operation,\n deliveryKey: Key,\n status: Schema.Literal(\"pending\"),\n providerDeliveryKey: Key,\n }),\n Schema.Struct({\n kind: Schema.Literal(\"deliver\"),\n ...operation,\n deliveryKey: Key,\n status: Schema.Literal(\"failed\"),\n code: Schema.Literals([\n \"rejected\",\n \"unauthorized\",\n \"rate_limited\",\n \"unavailable\",\n \"window_closed\",\n ]),\n }),\n Schema.Struct({\n kind: Schema.Literal(\"read_context\"),\n ...operation,\n // Without a version's features, any checked result: the host reads every version's.\n messages: Schema.Array(\n features === undefined || (features.assets && features.readContext === true)\n ? ContextMessage\n : TextContextMessage,\n ).check(Schema.isMaxLength(200)),\n }),\n ]);\n};\nconst readAssetCommand = <State extends Schema.Top>(state: State) =>\n Schema.Struct({\n asset: Asset,\n extensions: Schema.optionalKey(Extensions),\n identity: VerifiedIdentity,\n installationKey: Key,\n kind: Schema.Literal(\"read_asset\"),\n operationKey: Key,\n state,\n });\nconst readAssetResult = Schema.Struct({\n assetKey: Key,\n extensions: Schema.optionalKey(Extensions),\n file: AssetFile,\n kind: Schema.Literal(\"read_asset\"),\n operationKey: Key,\n});\nexport const commandSchema = <State extends Schema.Top>(state: State) =>\n Schema.Union([installedCommandSchema(state), readAssetCommand(state)]);\n/** Pass a version's features to check its results against its own contract. */\nexport const resultSchema = <State extends Schema.Top>(state: State, features?: Features) =>\n Schema.Union([installedResultSchema(state, features), readAssetResult]);\nexport type Command<State extends Schema.Top = Schema.Unknown> = ReturnType<\n typeof commandSchema<State>\n>[\"Type\"];\nexport type Result<State extends Schema.Top = Schema.Unknown> = ReturnType<\n typeof resultSchema<State>\n>[\"Type\"];\n/** Maximum UTF-8 bytes in an ordinary Channel command or result, including its JSON envelope. */\nexport const resultByteLimit = 2_097_152;\n/** Keep the newest context messages within the checked result budget, oldest first. */\nexport function contextResult(\n operationKey: string,\n context: readonly ContextMessage[],\n): Extract<Result, { readonly kind: \"read_context\" }> {\n const messages: ContextMessage[] = [];\n const result = { kind: \"read_context\" as const, messages, operationKey };\n const encoder = new TextEncoder();\n let bytes = encoder.encode(JSON.stringify(result)).byteLength;\n for (let index = context.length - 1; index >= 0; index--) {\n const message = context[index];\n if (message === undefined) continue;\n const size = encoder.encode(JSON.stringify(message)).byteLength + 1;\n if (bytes + size > resultByteLimit) break;\n bytes += size;\n messages.unshift(message);\n }\n return result;\n}\n/** Encoded, JSON-safe runtime result suitable for host persistence. */\nexport const CheckedResult = resultSchema(Schema.Json);\nexport type CheckedResult = typeof CheckedResult.Type;\n\n/** Immutable catalog projection. Live schemas remain the execution validators. */\nexport const Contract = Schema.Struct({\n definitionSettingsSchemaJson: Schema.Json,\n deploymentSettingsSchemaJson: Schema.Json,\n exposure: Exposure,\n extensionsSchemaJson: Schema.Record(Schema.String, Schema.Json),\n featuresJson: Features.check(\n Schema.makeFilter(features => (features.operations ?? []).includes(\"present_outcome\")),\n ),\n operationInputSchemaJson: Schema.Json,\n operationOutputSchemaJson: Schema.Json,\n requiredChecks: RequiredChecks,\n stateSchemaJson: Schema.Json,\n});\nexport type Contract = typeof Contract.Type;\n\nexport interface Definition<\n Settings extends Schema.Top = Schema.Top,\n Mappings extends Schema.Top = Schema.Top,\n State extends Schema.Top = Schema.Top,\n Methods extends readonly AuthMethod.Any[] = readonly AuthMethod.Any[],\n> {\n readonly definitionSettings: Settings;\n readonly deploymentSettings: Mappings;\n readonly state: State;\n readonly features: Features;\n readonly exposure: typeof Exposure.Type;\n readonly requiredChecks: typeof RequiredChecks.Type;\n /** Explicit subset of the provider's methods; [] means the channel accepts no connection. */\n readonly authMethods: Methods;\n /** Each key is provider/name. Values are checked on every command/result/event. */\n readonly extensions?: Readonly<Record<string, Schema.Top>>;\n}\n/** Project the exact declaration once for SDK discovery and server contract comparison. */\nexport const projectContract = (\n definition: Definition,\n project: (schema: Schema.Top) => unknown = schema =>\n Schema.toJsonSchemaDocument(schema, { onExcessProperty: \"error\" }),\n): Contract =>\n Schema.decodeUnknownSync(Contract)(\n {\n definitionSettingsSchemaJson: project(definition.definitionSettings),\n deploymentSettingsSchemaJson: project(definition.deploymentSettings),\n exposure: definition.exposure,\n extensionsSchemaJson: Object.fromEntries(\n Object.entries(definition.extensions ?? {}).map(([key, schema]) => [key, project(schema)]),\n ),\n featuresJson: definition.features,\n operationInputSchemaJson: project(commandSchema(definition.state)),\n operationOutputSchemaJson: project(resultSchema(definition.state, definition.features)),\n requiredChecks: definition.requiredChecks,\n stateSchemaJson: project(definition.state),\n },\n { onExcessProperty: \"error\" },\n );\nexport interface Any extends Pipeable.Pipeable {\n readonly [TypeId]: TypeId;\n readonly identifier: string;\n readonly name: string | undefined;\n readonly description: string | undefined;\n readonly definition: Definition;\n}\nexport interface AgentChannel<\n out Identifier extends string = string,\n out D extends Definition = Definition,\n> extends Any {\n readonly identifier: Identifier;\n readonly definition: D;\n}\nexport type ResolvedAuth<Methods extends readonly AuthMethod.Any[]> =\n Methods[number] extends infer M\n ? M extends AuthMethod.Any\n ? { readonly methodId: M[\"identifier\"]; readonly value: AuthMethod.Value<M> }\n : never\n : never;\nexport type HandlerContext<D extends Definition> = {\n readonly definitionSettings: D[\"definitionSettings\"][\"Type\"];\n readonly deploymentSettings: D[\"deploymentSettings\"][\"Type\"];\n} & (D[\"authMethods\"] extends readonly []\n ? {}\n : number extends D[\"authMethods\"][\"length\"]\n ? { readonly auth?: ResolvedAuth<D[\"authMethods\"]> }\n : { readonly auth: ResolvedAuth<D[\"authMethods\"]> });\n/** The command a Channel's handler receives. */\nexport type CommandFor<D extends Definition> = Command<D[\"state\"]>;\n/** The result a Channel's handler returns. */\nexport type ResultFor<D extends Definition> = Result<D[\"state\"]>;\nexport interface RuntimeContract<D extends Definition, R = never> {\n readonly verify: (\n request: Request,\n context: HandlerContext<D>,\n ) => Effect.Effect<Verification, HandlerError, R>;\n readonly checkAccess: (\n identity: VerifiedIdentity,\n context: HandlerContext<D>,\n ) => Effect.Effect<AccessOutcome, HandlerError, R>;\n readonly execute: (\n command: CommandFor<D>,\n context: HandlerContext<D>,\n ) => Effect.Effect<ResultFor<D>, HandlerError, R>;\n}\n/** Erased service representation. Input and output are checked by AgentChannelRuntime. */\nexport interface Handler<Id extends string = string> {\n readonly channelId: Id;\n readonly context: Context.Context<never>;\n readonly runtime: {\n readonly verify: (\n request: unknown,\n context: unknown,\n ) => Effect.Effect<unknown, unknown, unknown>;\n readonly checkAccess: (\n identity: unknown,\n context: unknown,\n ) => Effect.Effect<unknown, unknown, unknown>;\n readonly execute: (\n command: unknown,\n context: unknown,\n ) => Effect.Effect<unknown, unknown, unknown>;\n };\n}\nexport const handlerKey = (channelId: string): string =>\n `@dual-os/sdk/AgentChannel/Handler/${channelId}`;\n\nconst SchemaDefinition = Schema.declare(Schema.isSchema);\n// Fail closed on holes such as Unknown nested inside an otherwise typed state schema.\nconst checkSchema = (schema: Schema.Top, allowOpaque = false): void => {\n const seen = new Set<SchemaAST.AST>();\n const visit = (ast: SchemaAST.AST): void => {\n if (seen.has(ast)) return;\n seen.add(ast);\n if (\n ast.annotations?.[\"parseOptions\"] !== undefined ||\n (ast.checks?.some(check => check.annotations?.[\"parseOptions\"] !== undefined) ?? false)\n ) {\n throw new ChannelError({ code: \"invalid_definition\" });\n }\n ast.encoding?.forEach(link => {\n visit(link.to);\n });\n Match.value(ast).pipe(\n Match.tag(\"Unknown\", \"Any\", \"ObjectKeyword\", () => {\n throw new ChannelError({ code: \"invalid_definition\" });\n }),\n Match.tag(\"Declaration\", declaration => {\n if (!allowOpaque) throw new ChannelError({ code: \"invalid_definition\" });\n declaration.typeParameters.forEach(visit);\n }),\n Match.tag(\"Objects\", objects => {\n objects.propertySignatures.forEach(property => visit(property.type));\n objects.indexSignatures.forEach(index => {\n // Filtered keys may disappear silently; a channel contract must retain them.\n if (\n index.parameter._tag !== \"String\" ||\n index.parameter.checks !== undefined ||\n index.parameter.encoding !== undefined\n ) {\n throw new ChannelError({ code: \"invalid_definition\" });\n }\n visit(index.parameter);\n visit(index.type);\n });\n }),\n Match.tag(\"Arrays\", arrays => {\n arrays.elements.forEach(visit);\n arrays.rest.forEach(visit);\n }),\n Match.tag(\"Union\", union => {\n union.types.forEach(visit);\n }),\n Match.tag(\"Suspend\", suspend => {\n visit(suspend.thunk());\n }),\n Match.orElse(() => undefined),\n );\n };\n visit(schema.ast);\n};\nconst DefinitionSchema = Schema.Struct({\n authMethods: Schema.Array(Schema.declare(AuthMethod.isAuthMethod)),\n definitionSettings: SchemaDefinition,\n deploymentSettings: SchemaDefinition,\n exposure: Exposure,\n extensions: Schema.optionalKey(\n Schema.Record(Schema.String, SchemaDefinition).check(\n Schema.makeFilter(values => Object.keys(values).every(Schema.is(ExtensionKey))),\n ),\n ),\n features: Features,\n requiredChecks: RequiredChecks,\n state: SchemaDefinition,\n}).check(\n Schema.makeFilter(({ features }) => {\n const operations = features.operations ?? [];\n return (\n operations.includes(\"present_outcome\") &&\n new Set(operations).size === operations.length &&\n // A long text arrives as messages before its outcome.\n (features.maxTextLength === undefined || operations.includes(\"create_message\"))\n );\n }),\n);\n\n/** Validate declarations at registration as well as at builder time. */\nexport const validateDefinition = (\n definition: Definition,\n providerId?: string,\n methods?: readonly AuthMethod.Any[],\n): void => {\n try {\n Schema.decodeUnknownSync(DefinitionSchema)(definition, { onExcessProperty: \"error\" });\n for (const schema of [\n definition.definitionSettings,\n definition.deploymentSettings,\n definition.state,\n ...Object.values(definition.extensions ?? {}),\n ]) {\n // A JSON projection must exist; it is catalog metadata, never the execution validator.\n checkSchema(schema);\n Schema.toJsonSchemaDocument(schema);\n }\n const seen = new Set<string>();\n for (const method of definition.authMethods) {\n if (seen.has(method.identifier) || (methods !== undefined && !methods.includes(method))) {\n throw new ChannelError({ code: \"invalid_definition\" });\n }\n seen.add(method.identifier);\n Schema.decodeUnknownSync(SchemaDefinition)(method.material);\n Schema.decodeUnknownSync(SchemaDefinition)(method.value);\n for (const schema of [\n method.material,\n method.value,\n ...(method.setup === undefined ? [] : [method.setup]),\n ]) {\n checkSchema(schema, true);\n }\n }\n if (\n providerId !== undefined &&\n Object.keys(definition.extensions ?? {}).some(key => !key.startsWith(`${providerId}/`))\n ) {\n throw new ChannelError({ code: \"invalid_definition\" });\n }\n } catch {\n throw new ChannelError({ code: \"invalid_definition\" });\n }\n};\n\nexport interface ChannelOptions {\n readonly name?: string;\n readonly description?: string;\n}\n\n/** Create a Channel from its contract. */\nexport const make = <const Id extends string, const O extends Definition & ChannelOptions>(\n identifier: Id,\n options: O,\n): AgentChannel<Id, O> => {\n validateIdentifier(\"agent-channel\", identifier);\n const { description, name, ...definition }: Definition & ChannelOptions = options;\n validateDefinition(definition);\n return {\n ...PipeableProto,\n [TypeId]: TypeId,\n definition: Object.freeze({\n ...definition,\n authMethods: Object.freeze([...definition.authMethods]),\n features: Object.freeze({ ...definition.features }),\n requiredChecks: Object.freeze([...definition.requiredChecks]),\n ...(definition.extensions === undefined\n ? {}\n : { extensions: Object.freeze({ ...definition.extensions }) }),\n }),\n description,\n identifier,\n name,\n } as AgentChannel<Id, O>;\n};\nexport const isAgentChannel = (value: unknown): value is Any =>\n Predicate.hasProperty(value, TypeId);\n\nexport * as AgentChannel from \"./AgentChannel.ts\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AASA,MAAa,SAAS;;AAItB,MAAa,MAAM,OAAO,eAAe,MACvC,OAAO,YAAY,GAAG,GACtB,OAAO,UAAU,eAAe,CAClC;;AAEA,MAAa,gBAAgB,OAAO,SAAS;CAC3C;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;AAED,MAAa,WAAW,OAAO,OAAO;CACpC,QAAQ,OAAO;;CAEf,cAAc,OAAO,SAAS,CAAC,cAAc,cAAc,CAAC;CAC5D,eAAe,OAAO;CACtB,YAAY,OAAO,QAAQ,IAAI;CAC/B,QAAQ,OAAO;;CAEf,eAAe,OAAO,YAAY,OAAO,IAAI,MAAM,OAAO,cAAc,CAAC,CAAC,CAAC;CAC3E,UAAU,OAAO;;;;;CAKjB,YAAY,OAAO,YA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CAAC,IACD,EAAE,YAAY,OAAO,OAAO,EAAE,GAAG,WAAW,WAAW,CAAC,EAAE;EAChE,CAAC;EACD;EACA;EACA;CACF;AACF;AACA,MAAa,kBAAkB,UAC7B,UAAU,YAAY,OAAO,MAAM"}
|
|
@@ -206,7 +206,7 @@ const layer = (plugins) => Layer.effect(Service, Effect.gen(function* () {
|
|
|
206
206
|
});
|
|
207
207
|
}
|
|
208
208
|
const output = yield* invokeHandler(handler.value, Effect.suspend(() => handler.value.runtime.execute(command, adapterContext)));
|
|
209
|
-
const result = yield* decodeData(resultSchema(Schema.toType(definition.state)), output, "invalid_result", kind === "read_asset");
|
|
209
|
+
const result = yield* decodeData(resultSchema(Schema.toType(definition.state), definition.features), output, "invalid_result", kind === "read_asset");
|
|
210
210
|
if (result.kind !== kind || result.operationKey !== operationKey || result.kind === "deliver" && result.deliveryKey !== deliveryKey || result.kind === "read_asset" && result.assetKey !== assetKey) return yield* fail("invalid_result");
|
|
211
211
|
yield* checkExtensions(definition, result.extensions, "invalid_result");
|
|
212
212
|
if (result.kind === "deliver" && result.status === "pending" && !definition.features.deliveryState) return yield* fail("invalid_result");
|
|
@@ -238,7 +238,7 @@ const layer = (plugins) => Layer.effect(Service, Effect.gen(function* () {
|
|
|
238
238
|
allowedEvents.push(event);
|
|
239
239
|
}
|
|
240
240
|
}
|
|
241
|
-
const encoded = yield* safe(Schema.encodeUnknownEffect(resultSchema(definition.state))(result.kind === "receive" ? {
|
|
241
|
+
const encoded = yield* safe(Schema.encodeUnknownEffect(resultSchema(definition.state, definition.features))(result.kind === "receive" ? {
|
|
242
242
|
...result,
|
|
243
243
|
events: allowedEvents,
|
|
244
244
|
...deniedEventKeys.length === 0 ? {} : { deniedEventKeys }
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AgentChannelRuntime.js","names":["AgentChannel.Key","AgentChannel.VerifiedIdentity","AgentChannel.ChannelError","AgentChannel.resultByteLimit","AgentChannel.FailureCode","ConnectionResolver.Service","AgentChannel.handlerKey","AgentChannel.AccessOutcome","AgentChannel.commandSchema","AgentChannel.Verification","AgentChannel.resultSchema","AgentChannel.CheckedResult"],"sources":["../src/AgentChannelRuntime.ts"],"sourcesContent":["/** Checked execution of pinned Agent Channel capabilities. No product lifecycle or persistence. */\nimport { Cause, Context, Effect, Layer, Option, Predicate, Schema } from \"effect\";\n\nimport * as AgentChannel from \"./AgentChannel.ts\";\nimport { ConnectionResolver } from \"./ConnectionResolver.ts\";\nimport type { AuthResolutionRequirements } from \"./internal/auth-execution.ts\";\nimport { findHandler } from \"./internal/handler-context.ts\";\nimport type * as Plugin from \"./Plugin.ts\";\n\n/** Host-only connection authority context. It is never included in handler inputs. */\nexport const ConnectionContext = Schema.Struct({\n actor: Schema.optionalKey(\n Schema.Union([\n Schema.Struct({ kind: Schema.Literal(\"user\"), userId: AgentChannel.Key }),\n Schema.Struct({\n kind: Schema.Literal(\"system\"),\n reason: Schema.optionalKey(AgentChannel.Key),\n }),\n ]),\n ),\n source: Schema.optionalKey(\n Schema.Struct({ kind: AgentChannel.Key, subjectId: Schema.optionalKey(AgentChannel.Key) }),\n ),\n tenant: Schema.optionalKey(\n Schema.Struct({ organizationId: AgentChannel.Key, teamId: AgentChannel.Key }),\n ),\n});\nconst Pin = Schema.Struct({ channelId: AgentChannel.Key });\nconst Input = Schema.Struct({\n ...Pin.fields,\n command: Schema.Unknown,\n connectionId: Schema.optionalKey(AgentChannel.Key),\n context: Schema.optionalKey(ConnectionContext),\n definitionSettings: Schema.Unknown,\n deploymentSettings: Schema.Unknown,\n});\nconst AccessInput = Schema.Struct({\n ...Pin.fields,\n connectionId: Schema.optionalKey(AgentChannel.Key),\n context: Schema.optionalKey(ConnectionContext),\n definitionSettings: Schema.Unknown,\n deploymentSettings: Schema.Unknown,\n identity: AgentChannel.VerifiedIdentity,\n});\nexport type Pin = typeof Pin.Type;\nexport type Input = typeof Input.Type;\nexport interface Interface {\n /** Reauthorize an already verified identity; does not verify a transport or execute provider operations. */\n readonly checkAccess: (\n input: unknown,\n ) => Effect.Effect<AgentChannel.AccessOutcome, AgentChannel.ChannelError>;\n readonly get: (pin: unknown) => Effect.Effect<AgentChannel.Definition, AgentChannel.ChannelError>;\n readonly decodeDefinitionSettings: (\n input: unknown,\n ) => Effect.Effect<Schema.Json, AgentChannel.ChannelError>;\n readonly decodeDeploymentSettings: (\n input: unknown,\n ) => Effect.Effect<Schema.Json, AgentChannel.ChannelError>;\n readonly execute: (\n input: unknown,\n ) => Effect.Effect<AgentChannel.CheckedResult, AgentChannel.ChannelError>;\n}\nexport class Service extends Context.Service<Service, Interface>()(\n \"@dual-os/sdk/AgentChannelRuntime\",\n) {}\n\ntype Definitions<P extends Plugin.Any> = P[\"agentChannels\"][number][\"definition\"];\ntype ChannelHandlers<P extends Plugin.Any, C> = C extends AgentChannel.Any\n ? AgentChannel.Handler<`${P[\"identifier\"]}/${C[\"identifier\"]}`>\n : never;\ntype PluginHandlers<P> = P extends Plugin.Any\n ? ChannelHandlers<P, P[\"agentChannels\"][number]>\n : never;\ntype ExtensionRequirements<D> = D extends {\n readonly extensions: infer Extensions extends Readonly<Record<string, Schema.Top>>;\n}\n ?\n | Extensions[keyof Extensions][\"DecodingServices\"]\n | Extensions[keyof Extensions][\"EncodingServices\"]\n : never;\nexport type Requirements<P extends Plugin.Any> =\n | PluginHandlers<P>\n | ExtensionRequirements<Definitions<P>>\n | Definitions<P>[\"definitionSettings\"][\"DecodingServices\"]\n | Definitions<P>[\"deploymentSettings\"][\"DecodingServices\"]\n | Definitions<P>[\"state\"][\"DecodingServices\"]\n | Definitions<P>[\"state\"][\"EncodingServices\"]\n | AuthResolutionRequirements<Definitions<P>[\"authMethods\"]>\n | (Definitions<P>[\"authMethods\"][number] extends never ? never : ConnectionResolver.Service);\n\nconst fail = (code: typeof AgentChannel.ErrorCode.Type) => new AgentChannel.ChannelError({ code });\nconst safe = <A, E, R>(\n effect: Effect.Effect<A, E, R>,\n code: typeof AgentChannel.ErrorCode.Type,\n): Effect.Effect<A, AgentChannel.ChannelError, R> =>\n effect.pipe(\n Effect.catchCause(cause =>\n Cause.hasInterrupts(cause) ? Effect.interrupt : Effect.fail(fail(code)),\n ),\n );\nconst AssetResultJson = Schema.Json.check(\n Schema.makeFilter(\n value => new TextEncoder().encode(JSON.stringify(value)).byteLength <= 14_680_064,\n ),\n);\nconst Json = Schema.Json.check(\n Schema.makeFilter(\n value =>\n new TextEncoder().encode(JSON.stringify(value)).byteLength <= AgentChannel.resultByteLimit,\n ),\n);\nconst strict = { onExcessProperty: \"error\" } as const;\nconst decode = <S extends Schema.Top>(\n schema: S,\n input: unknown,\n code: typeof AgentChannel.ErrorCode.Type,\n) =>\n safe(\n Effect.suspend(() => Schema.decodeUnknownEffect(schema)(input, strict)),\n code,\n );\nconst json = (value: unknown, code: typeof AgentChannel.ErrorCode.Type) =>\n decode(Json, value, code);\nconst decodeData = Effect.fn(\"AgentChannelRuntime.decodeData\")(function* <S extends Schema.Top>(\n schema: S,\n input: unknown,\n code: typeof AgentChannel.ErrorCode.Type,\n largeAssetResult = false,\n) {\n const boundary = largeAssetResult ? AssetResultJson : Json;\n yield* decode(boundary, input, code);\n const value = yield* decode(schema, input, code);\n yield* decode(boundary, value, code);\n return value;\n});\n\nconst invokeHandler = (\n handler: AgentChannel.Handler,\n effect: Effect.Effect<unknown, unknown, unknown>,\n) =>\n effect.pipe(\n Effect.provideContext(handler.context),\n Effect.catch(error =>\n decode(\n Schema.TaggedStruct(\"AgentChannelHandlerError\", { code: AgentChannel.FailureCode }),\n Predicate.isObject(error) ? { ...error } : error,\n \"provider_failure\",\n ).pipe(\n Effect.flatMap(checked =>\n Effect.fail(\n new AgentChannel.ChannelError({ code: \"provider_failure\", providerCode: checked.code }),\n ),\n ),\n ),\n ),\n Effect.catchCause(cause => {\n if (Cause.hasInterrupts(cause)) return Effect.interrupt;\n const error = Cause.findErrorOption(cause);\n return Option.isSome(error) && error.value instanceof AgentChannel.ChannelError\n ? Effect.fail(error.value)\n : Effect.fail(fail(\"provider_failure\"));\n }),\n );\n\nconst checkExtensions = Effect.fn(\"AgentChannelRuntime.checkExtensions\")(function* (\n definition: AgentChannel.Definition,\n extensions: Readonly<Record<string, Schema.Json>> | undefined,\n code: typeof AgentChannel.ErrorCode.Type,\n) {\n for (const [key, value] of Object.entries(extensions ?? {})) {\n const schema = definition.extensions?.[key];\n if (schema === undefined) return yield* fail(code);\n // Extensions are checked values, not a provider payload escape hatch. No normalization.\n yield* decodeData(Schema.toType(schema), value, code);\n }\n});\nconst checkMessage = (\n features: AgentChannel.Features,\n destination: AgentChannel.Destination,\n content: AgentChannel.Content,\n): boolean =>\n (destination.kind === \"direct\" || features.groups) &&\n (destination.threadKey === undefined || features.threads) &&\n (content.mentions === undefined || features.mentions) &&\n (content.assets === undefined || features.assets) &&\n (content.replyToMessageKey === undefined || features.replies);\n\nconst checkDelivery = (\n features: AgentChannel.Features,\n command: Extract<AgentChannel.Command, { kind: \"deliver\" }>,\n): boolean =>\n checkMessage(features, command.destination, { text: \"\" }) &&\n (features.operations ?? []).includes(command.operation.kind);\n\nconst Material = Schema.Struct({\n connectionId: AgentChannel.Key,\n // The plugin worker's resolver marks its JSON-carried material.\n encoding: Schema.optionalKey(Schema.Literal(\"json\")),\n material: Schema.Unknown,\n methodId: AgentChannel.Key,\n providerId: AgentChannel.Key,\n setup: Schema.Unknown,\n});\nconst ResolveHook = Schema.declare(\n (value): value is (material: unknown, context: { readonly setup: unknown }) => unknown =>\n Predicate.isFunction(value),\n);\nconst resolveAuth = Effect.fn(\"AgentChannelRuntime.resolveAuth\")(function* (\n providerId: string,\n channelId: string,\n definition: AgentChannel.Definition,\n connectionId: string | undefined,\n phase: string,\n context: typeof ConnectionContext.Type | undefined,\n) {\n if (definition.authMethods.length === 0) {\n if (connectionId !== undefined) return yield* fail(\"invalid_auth\");\n return undefined;\n }\n // The host alone selects/authorizes the pinned connection. Its records never reach the plugin.\n if (connectionId === undefined) return yield* fail(\"invalid_auth\");\n const resolver = yield* Effect.serviceOption(ConnectionResolver.Service);\n if (Option.isNone(resolver)) return yield* fail(\"invalid_auth\");\n const raw = yield* safe(\n Effect.suspend(() =>\n resolver.value.resolve({\n connectionId,\n target: { phase, providerId, targetId: channelId, targetKind: \"agent-channel\" },\n ...(context === undefined ? {} : { context }),\n }),\n ),\n \"invalid_auth\",\n );\n const resolved = yield* decode(Material, raw, \"invalid_auth\");\n if (resolved.providerId !== providerId || resolved.connectionId !== connectionId) {\n return yield* fail(\"invalid_auth\");\n }\n const method = definition.authMethods.find(\n method =>\n resolved.methodId === method.identifier ||\n resolved.methodId === `${providerId}/${method.identifier}`,\n );\n if (method === undefined) return yield* fail(\"invalid_auth\");\n // Material the worker received as JSON decodes through each schema's JSON codec.\n const decodeAuth = <S extends Schema.Top>(schema: S, value: unknown) =>\n decode(\n resolved.encoding === \"json\" ? Schema.toCodecJson(schema) : schema,\n value,\n \"invalid_auth\",\n );\n const setup =\n method.setup === undefined\n ? yield* decode(Schema.Undefined, resolved.setup, \"invalid_auth\")\n : yield* decodeAuth(method.setup, resolved.setup);\n const material = yield* decodeAuth(method.material, resolved.material);\n let value: unknown;\n if (method.resolve === undefined) {\n value =\n method.material === method.value\n ? material\n : yield* decode(method.value, material, \"invalid_auth\");\n } else {\n const hook = yield* decode(ResolveHook, method.resolve, \"invalid_auth\");\n const output = yield* safe(\n Effect.suspend(() => {\n const result = hook(material, { setup });\n return Effect.isEffect(result) ? result : Effect.succeed(result);\n }),\n \"invalid_auth\",\n );\n value = yield* decode(method.value, output, \"invalid_auth\");\n }\n // Schemas may use Redacted for auth. Only this checked value, never material/setup/binding,\n // is exposed to the command handler.\n return { methodId: method.identifier, value };\n});\n\nconst find = (plugins: readonly Plugin.Any[], pin: Pin) => {\n for (const provider of plugins) {\n const channel = provider.agentChannels.find(\n channel => `${provider.identifier}/${channel.identifier}` === pin.channelId,\n );\n if (channel !== undefined) return { definition: channel.definition, provider };\n }\n return undefined;\n};\n\n/** Build from the installed plugins. */\nexport const layer = <P extends Plugin.Any>(\n plugins: readonly P[],\n): Layer.Layer<Service, never, Requirements<P>> =>\n Layer.effect(\n Service,\n Effect.gen(function* () {\n const context = yield* Effect.context<Requirements<P>>();\n const get = Effect.fn(\"AgentChannelRuntime.get\")(function* (input: unknown) {\n const pin = yield* decode(Pin, input, \"invalid_input\");\n const found = find(plugins, pin);\n if (found === undefined) return yield* fail(\"not_found\");\n yield* safe(\n Effect.sync(() => {\n AgentChannel.validateDefinition(\n found.definition,\n found.provider.identifier,\n found.provider.authMethods,\n );\n }),\n \"invalid_definition\",\n );\n const handler = Option.fromNullishOr(\n findHandler(\n context,\n found.provider.identifier,\n AgentChannel.handlerKey(pin.channelId),\n ) as AgentChannel.Handler | undefined,\n );\n if (\n Option.isNone(handler) ||\n !Predicate.isObject(handler.value.runtime) ||\n !Predicate.isFunction(handler.value.runtime.execute) ||\n !Predicate.isFunction(handler.value.runtime.verify) ||\n !Predicate.isFunction(handler.value.runtime.checkAccess)\n ) {\n return yield* fail(\"handler_unavailable\");\n }\n return found.definition;\n });\n const checkAccess = Effect.fn(\"AgentChannelRuntime.checkAccess\")(function* (input: unknown) {\n yield* json(input, \"invalid_input\");\n const request = yield* decode(AccessInput, input, \"invalid_input\");\n const definition = yield* get({ channelId: request.channelId });\n const found = find(plugins, request);\n if (found === undefined) return yield* fail(\"not_found\");\n const definitionSettings = yield* decodeData(\n definition.definitionSettings,\n request.definitionSettings,\n \"invalid_input\",\n );\n const deploymentSettings = yield* decodeData(\n definition.deploymentSettings,\n request.deploymentSettings,\n \"invalid_input\",\n );\n if (!checkMessage(definition.features, request.identity.conversation, { text: \"\" })) {\n return yield* fail(\"unsupported_feature\");\n }\n const auth = yield* resolveAuth(\n found.provider.identifier,\n request.channelId,\n definition,\n request.connectionId,\n \"check_access\",\n request.context,\n );\n const handler = Option.fromNullishOr(\n findHandler(\n context,\n found.provider.identifier,\n AgentChannel.handlerKey(request.channelId),\n ) as AgentChannel.Handler | undefined,\n );\n if (Option.isNone(handler)) return yield* fail(\"handler_unavailable\");\n const output = yield* invokeHandler(\n handler.value,\n Effect.suspend(() =>\n handler.value.runtime.checkAccess(request.identity, {\n definitionSettings,\n deploymentSettings,\n ...(auth === undefined ? {} : { auth }),\n }),\n ),\n );\n return yield* decodeData(AgentChannel.AccessOutcome, output, \"invalid_result\");\n });\n const execute = Effect.fn(\"AgentChannelRuntime.execute\")(function* (input: unknown) {\n yield* json(input, \"invalid_input\");\n const request = yield* decode(Input, input, \"invalid_input\");\n const definition = yield* get({ channelId: request.channelId });\n const found = find(plugins, request);\n if (found === undefined) return yield* fail(\"not_found\");\n const definitionSettings = yield* decodeData(\n definition.definitionSettings,\n request.definitionSettings,\n \"invalid_input\",\n );\n const deploymentSettings = yield* decodeData(\n definition.deploymentSettings,\n request.deploymentSettings,\n \"invalid_input\",\n );\n const command: AgentChannel.Command = yield* decodeData(\n AgentChannel.commandSchema(definition.state),\n request.command,\n \"invalid_input\",\n );\n yield* checkExtensions(definition, command.extensions, \"invalid_input\");\n if (command.kind === \"deliver\" && command.operationKey !== command.deliveryKey) {\n return yield* fail(\"invalid_input\");\n }\n if (command.kind === \"deliver\" && !checkDelivery(definition.features, command)) {\n return yield* fail(\"unsupported_feature\");\n }\n if (\n command.kind === \"deliver\" &&\n command.operation.kind === \"set_reaction\" &&\n command.operation.target.kind === \"activation\" &&\n command.activationMessageKey === undefined\n ) {\n return yield* fail(\"invalid_input\");\n }\n if (\n command.kind === \"read_context\" &&\n (definition.features.readContext !== true ||\n !checkMessage(definition.features, command.destination, { text: \"\" }))\n ) {\n return yield* fail(\"unsupported_feature\");\n }\n const handler = Option.fromNullishOr(\n findHandler(\n context,\n found.provider.identifier,\n AgentChannel.handlerKey(request.channelId),\n ) as AgentChannel.Handler | undefined,\n );\n if (Option.isNone(handler)) return yield* fail(\"handler_unavailable\");\n const auth = yield* resolveAuth(\n found.provider.identifier,\n request.channelId,\n definition,\n request.connectionId,\n command.kind,\n request.context,\n );\n // Keep correlation facts independent of any mutation by provider code.\n const operationKey = command.operationKey;\n const kind = command.kind;\n const deliveryKey = command.kind === \"deliver\" ? command.deliveryKey : undefined;\n const assetKey = command.kind === \"read_asset\" ? command.asset.assetKey : undefined;\n const adapterContext = {\n definitionSettings,\n deploymentSettings,\n ...(auth === undefined ? {} : { auth }),\n };\n if (\n !Predicate.isFunction(handler.value.runtime.execute) ||\n !Predicate.isFunction(handler.value.runtime.verify) ||\n !Predicate.isFunction(handler.value.runtime.checkAccess)\n ) {\n return yield* fail(\"handler_unavailable\");\n }\n if (command.kind === \"receive\") {\n yield* decodeData(\n AgentChannel.Verification,\n yield* invokeHandler(\n handler.value,\n Effect.suspend(() => handler.value.runtime.verify(command.request, adapterContext)),\n ),\n \"invalid_result\",\n );\n }\n if (command.kind === \"read_asset\") {\n if (!definition.features.assets) return yield* fail(\"unsupported_feature\");\n const decision = yield* decodeData(\n AgentChannel.AccessOutcome,\n yield* invokeHandler(\n handler.value,\n Effect.suspend(() =>\n handler.value.runtime.checkAccess(command.identity, adapterContext),\n ),\n ),\n \"invalid_result\",\n );\n if (decision.decision !== \"allow\") {\n return yield* new AgentChannel.ChannelError({\n code: \"provider_failure\",\n providerCode: \"unauthorized\",\n });\n }\n }\n const output = yield* invokeHandler(\n handler.value,\n Effect.suspend(() => handler.value.runtime.execute(command, adapterContext)),\n );\n const result: AgentChannel.Result = yield* decodeData(\n AgentChannel.resultSchema(Schema.toType(definition.state)),\n output,\n \"invalid_result\",\n kind === \"read_asset\",\n );\n if (\n result.kind !== kind ||\n result.operationKey !== operationKey ||\n (result.kind === \"deliver\" && result.deliveryKey !== deliveryKey) ||\n (result.kind === \"read_asset\" && result.assetKey !== assetKey)\n ) {\n return yield* fail(\"invalid_result\");\n }\n yield* checkExtensions(definition, result.extensions, \"invalid_result\");\n if (\n result.kind === \"deliver\" &&\n result.status === \"pending\" &&\n !definition.features.deliveryState\n ) {\n return yield* fail(\"invalid_result\");\n }\n const allowedEvents: AgentChannel.Event[] = [];\n const deniedEventKeys: string[] = [];\n if (result.kind === \"receive\") {\n if (result.deniedEventKeys !== undefined) return yield* fail(\"invalid_result\");\n if (\n result.activationProof === \"verified\" &&\n (result.response === undefined || result.events.length !== 0)\n ) {\n return yield* fail(\"invalid_result\");\n }\n const eventKeys = new Set<string>();\n for (const event of result.events) {\n if (eventKeys.has(event.eventKey)) return yield* fail(\"invalid_result\");\n eventKeys.add(event.eventKey);\n if (\n event.kind === \"message\" &&\n !checkMessage(definition.features, event.conversation, event.content)\n ) {\n return yield* fail(\"invalid_result\");\n }\n if (\n (event.kind === \"echo\" || event.kind === \"stop\") &&\n !checkMessage(definition.features, event.conversation, { text: \"\" })\n ) {\n return yield* fail(\"invalid_result\");\n }\n if (event.kind === \"delivery_update\" && !definition.features.deliveryState) {\n return yield* fail(\"invalid_result\");\n }\n yield* checkExtensions(definition, event.extensions, \"invalid_result\");\n let denied = false;\n if (event.kind === \"message\" || event.kind === \"echo\" || event.kind === \"stop\") {\n const identity = yield* decodeData(\n AgentChannel.VerifiedIdentity,\n { conversation: event.conversation, senderKey: event.senderKey },\n \"invalid_result\",\n );\n const decision = yield* decodeData(\n AgentChannel.AccessOutcome,\n yield* invokeHandler(\n handler.value,\n Effect.suspend(() => handler.value.runtime.checkAccess(identity, adapterContext)),\n ),\n \"invalid_result\",\n );\n denied = decision.decision === \"deny\";\n }\n if (denied) {\n deniedEventKeys.push(event.eventKey);\n continue;\n }\n allowedEvents.push(event);\n }\n }\n // Store the encoded state so subsequent pinned commands can decode it exactly once.\n const encoded = yield* safe(\n Schema.encodeUnknownEffect(AgentChannel.resultSchema(definition.state))(\n result.kind === \"receive\"\n ? {\n ...result,\n events: allowedEvents,\n ...(deniedEventKeys.length === 0 ? {} : { deniedEventKeys }),\n }\n : result,\n strict,\n ),\n \"invalid_result\",\n );\n return yield* decodeData(\n AgentChannel.CheckedResult,\n encoded,\n \"invalid_result\",\n kind === \"read_asset\",\n );\n });\n // SAFETY: Requirements above account for each schema, auth method and Channel handler. The\n // dynamic lookup erases their union; the captured application context discharges it here.\n const run = <A>(\n effect: Effect.Effect<A, AgentChannel.ChannelError, unknown>,\n ): Effect.Effect<A, AgentChannel.ChannelError> =>\n // @effect-diagnostics-next-line unsafeEffectTypeAssertion:off -- Channel handlers are checked and their captured context satisfies the declared Requirements (SAFETY above).\n effect.pipe(Effect.provideContext(context)) as Effect.Effect<A, AgentChannel.ChannelError>;\n const decodeSettings = (field: \"definitionSettings\" | \"deploymentSettings\") =>\n Effect.fn(\"AgentChannelRuntime.decodeSettings\")(function* (input: unknown) {\n const request = yield* decode(\n Schema.Struct({ ...Pin.fields, value: Schema.Json }),\n input,\n \"invalid_input\",\n );\n const definition = yield* get({ channelId: request.channelId });\n const schema = definition[field];\n const value = yield* decodeData(schema, request.value, \"invalid_input\");\n return yield* json(\n yield* safe(Schema.encodeUnknownEffect(schema)(value, strict), \"invalid_input\"),\n \"invalid_input\",\n );\n });\n return Service.of({\n checkAccess: input => run(checkAccess(input)),\n decodeDefinitionSettings: input => run(decodeSettings(\"definitionSettings\")(input)),\n decodeDeploymentSettings: input => run(decodeSettings(\"deploymentSettings\")(input)),\n execute: input => run(execute(input)),\n get: input => run(get(input)),\n });\n }),\n );\n\nexport * as AgentChannelRuntime from \"./AgentChannelRuntime.ts\";\n"],"mappings":";;;;;;;;;;;;;;;AAUA,MAAa,oBAAoB,OAAO,OAAO;CAC7C,OAAO,OAAO,YACZ,OAAO,MAAM,CACX,OAAO,OAAO;EAAE,MAAM,OAAO,QAAQ,MAAM;EAAG,QAAQA;CAAiB,CAAC,GACxE,OAAO,OAAO;EACZ,MAAM,OAAO,QAAQ,QAAQ;EAC7B,QAAQ,OAAO,YAAYA,GAAgB;CAC7C,CAAC,CACH,CAAC,CACH;CACA,QAAQ,OAAO,YACb,OAAO,OAAO;EAAE,MAAMA;EAAkB,WAAW,OAAO,YAAYA,GAAgB;CAAE,CAAC,CAC3F;CACA,QAAQ,OAAO,YACb,OAAO,OAAO;EAAE,gBAAgB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pC;EAC1B,MAAM,QAAQ,OAAO,WAAW,QAAQ,QAAQ,OAAO,eAAe;EACtE,OAAO,OAAO,KACZ,OAAO,KAAK,OAAO,oBAAoB,MAAM,CAAC,CAAC,OAAO,MAAM,GAAG,eAAe,GAC9E,eACF;CACF,CAAC;CACH,OAAO,QAAQ,GAAG;EAChB,cAAa,UAAS,IAAI,YAAY,KAAK,CAAC;EAC5C,2BAA0B,UAAS,IAAI,eAAe,oBAAoB,CAAC,CAAC,KAAK,CAAC;EAClF,2BAA0B,UAAS,IAAI,eAAe,oBAAoB,CAAC,CAAC,KAAK,CAAC;EAClF,UAAS,UAAS,IAAI,QAAQ,KAAK,CAAC;EACpC,MAAK,UAAS,IAAI,IAAI,KAAK,CAAC;CAC9B,CAAC;AACH,CAAC,CACH"}
|
|
1
|
+
{"version":3,"file":"AgentChannelRuntime.js","names":["AgentChannel.Key","AgentChannel.VerifiedIdentity","AgentChannel.ChannelError","AgentChannel.resultByteLimit","AgentChannel.FailureCode","ConnectionResolver.Service","AgentChannel.handlerKey","AgentChannel.AccessOutcome","AgentChannel.commandSchema","AgentChannel.Verification","AgentChannel.resultSchema","AgentChannel.CheckedResult"],"sources":["../src/AgentChannelRuntime.ts"],"sourcesContent":["/** Checked execution of pinned Agent Channel capabilities. No product lifecycle or persistence. */\nimport { Cause, Context, Effect, Layer, Option, Predicate, Schema } from \"effect\";\n\nimport * as AgentChannel from \"./AgentChannel.ts\";\nimport { ConnectionResolver } from \"./ConnectionResolver.ts\";\nimport type { AuthResolutionRequirements } from \"./internal/auth-execution.ts\";\nimport { findHandler } from \"./internal/handler-context.ts\";\nimport type * as Plugin from \"./Plugin.ts\";\n\n/** Host-only connection authority context. It is never included in handler inputs. */\nexport const ConnectionContext = Schema.Struct({\n actor: Schema.optionalKey(\n Schema.Union([\n Schema.Struct({ kind: Schema.Literal(\"user\"), userId: AgentChannel.Key }),\n Schema.Struct({\n kind: Schema.Literal(\"system\"),\n reason: Schema.optionalKey(AgentChannel.Key),\n }),\n ]),\n ),\n source: Schema.optionalKey(\n Schema.Struct({ kind: AgentChannel.Key, subjectId: Schema.optionalKey(AgentChannel.Key) }),\n ),\n tenant: Schema.optionalKey(\n Schema.Struct({ organizationId: AgentChannel.Key, teamId: AgentChannel.Key }),\n ),\n});\nconst Pin = Schema.Struct({ channelId: AgentChannel.Key });\nconst Input = Schema.Struct({\n ...Pin.fields,\n command: Schema.Unknown,\n connectionId: Schema.optionalKey(AgentChannel.Key),\n context: Schema.optionalKey(ConnectionContext),\n definitionSettings: Schema.Unknown,\n deploymentSettings: Schema.Unknown,\n});\nconst AccessInput = Schema.Struct({\n ...Pin.fields,\n connectionId: Schema.optionalKey(AgentChannel.Key),\n context: Schema.optionalKey(ConnectionContext),\n definitionSettings: Schema.Unknown,\n deploymentSettings: Schema.Unknown,\n identity: AgentChannel.VerifiedIdentity,\n});\nexport type Pin = typeof Pin.Type;\nexport type Input = typeof Input.Type;\nexport interface Interface {\n /** Reauthorize an already verified identity; does not verify a transport or execute provider operations. */\n readonly checkAccess: (\n input: unknown,\n ) => Effect.Effect<AgentChannel.AccessOutcome, AgentChannel.ChannelError>;\n readonly get: (pin: unknown) => Effect.Effect<AgentChannel.Definition, AgentChannel.ChannelError>;\n readonly decodeDefinitionSettings: (\n input: unknown,\n ) => Effect.Effect<Schema.Json, AgentChannel.ChannelError>;\n readonly decodeDeploymentSettings: (\n input: unknown,\n ) => Effect.Effect<Schema.Json, AgentChannel.ChannelError>;\n readonly execute: (\n input: unknown,\n ) => Effect.Effect<AgentChannel.CheckedResult, AgentChannel.ChannelError>;\n}\nexport class Service extends Context.Service<Service, Interface>()(\n \"@dual-os/sdk/AgentChannelRuntime\",\n) {}\n\ntype Definitions<P extends Plugin.Any> = P[\"agentChannels\"][number][\"definition\"];\ntype ChannelHandlers<P extends Plugin.Any, C> = C extends AgentChannel.Any\n ? AgentChannel.Handler<`${P[\"identifier\"]}/${C[\"identifier\"]}`>\n : never;\ntype PluginHandlers<P> = P extends Plugin.Any\n ? ChannelHandlers<P, P[\"agentChannels\"][number]>\n : never;\ntype ExtensionRequirements<D> = D extends {\n readonly extensions: infer Extensions extends Readonly<Record<string, Schema.Top>>;\n}\n ?\n | Extensions[keyof Extensions][\"DecodingServices\"]\n | Extensions[keyof Extensions][\"EncodingServices\"]\n : never;\nexport type Requirements<P extends Plugin.Any> =\n | PluginHandlers<P>\n | ExtensionRequirements<Definitions<P>>\n | Definitions<P>[\"definitionSettings\"][\"DecodingServices\"]\n | Definitions<P>[\"deploymentSettings\"][\"DecodingServices\"]\n | Definitions<P>[\"state\"][\"DecodingServices\"]\n | Definitions<P>[\"state\"][\"EncodingServices\"]\n | AuthResolutionRequirements<Definitions<P>[\"authMethods\"]>\n | (Definitions<P>[\"authMethods\"][number] extends never ? never : ConnectionResolver.Service);\n\nconst fail = (code: typeof AgentChannel.ErrorCode.Type) => new AgentChannel.ChannelError({ code });\nconst safe = <A, E, R>(\n effect: Effect.Effect<A, E, R>,\n code: typeof AgentChannel.ErrorCode.Type,\n): Effect.Effect<A, AgentChannel.ChannelError, R> =>\n effect.pipe(\n Effect.catchCause(cause =>\n Cause.hasInterrupts(cause) ? Effect.interrupt : Effect.fail(fail(code)),\n ),\n );\nconst AssetResultJson = Schema.Json.check(\n Schema.makeFilter(\n value => new TextEncoder().encode(JSON.stringify(value)).byteLength <= 14_680_064,\n ),\n);\nconst Json = Schema.Json.check(\n Schema.makeFilter(\n value =>\n new TextEncoder().encode(JSON.stringify(value)).byteLength <= AgentChannel.resultByteLimit,\n ),\n);\nconst strict = { onExcessProperty: \"error\" } as const;\nconst decode = <S extends Schema.Top>(\n schema: S,\n input: unknown,\n code: typeof AgentChannel.ErrorCode.Type,\n) =>\n safe(\n Effect.suspend(() => Schema.decodeUnknownEffect(schema)(input, strict)),\n code,\n );\nconst json = (value: unknown, code: typeof AgentChannel.ErrorCode.Type) =>\n decode(Json, value, code);\nconst decodeData = Effect.fn(\"AgentChannelRuntime.decodeData\")(function* <S extends Schema.Top>(\n schema: S,\n input: unknown,\n code: typeof AgentChannel.ErrorCode.Type,\n largeAssetResult = false,\n) {\n const boundary = largeAssetResult ? AssetResultJson : Json;\n yield* decode(boundary, input, code);\n const value = yield* decode(schema, input, code);\n yield* decode(boundary, value, code);\n return value;\n});\n\nconst invokeHandler = (\n handler: AgentChannel.Handler,\n effect: Effect.Effect<unknown, unknown, unknown>,\n) =>\n effect.pipe(\n Effect.provideContext(handler.context),\n Effect.catch(error =>\n decode(\n Schema.TaggedStruct(\"AgentChannelHandlerError\", { code: AgentChannel.FailureCode }),\n Predicate.isObject(error) ? { ...error } : error,\n \"provider_failure\",\n ).pipe(\n Effect.flatMap(checked =>\n Effect.fail(\n new AgentChannel.ChannelError({ code: \"provider_failure\", providerCode: checked.code }),\n ),\n ),\n ),\n ),\n Effect.catchCause(cause => {\n if (Cause.hasInterrupts(cause)) return Effect.interrupt;\n const error = Cause.findErrorOption(cause);\n return Option.isSome(error) && error.value instanceof AgentChannel.ChannelError\n ? Effect.fail(error.value)\n : Effect.fail(fail(\"provider_failure\"));\n }),\n );\n\nconst checkExtensions = Effect.fn(\"AgentChannelRuntime.checkExtensions\")(function* (\n definition: AgentChannel.Definition,\n extensions: Readonly<Record<string, Schema.Json>> | undefined,\n code: typeof AgentChannel.ErrorCode.Type,\n) {\n for (const [key, value] of Object.entries(extensions ?? {})) {\n const schema = definition.extensions?.[key];\n if (schema === undefined) return yield* fail(code);\n // Extensions are checked values, not a provider payload escape hatch. No normalization.\n yield* decodeData(Schema.toType(schema), value, code);\n }\n});\nconst checkMessage = (\n features: AgentChannel.Features,\n destination: AgentChannel.Destination,\n content: AgentChannel.Content,\n): boolean =>\n (destination.kind === \"direct\" || features.groups) &&\n (destination.threadKey === undefined || features.threads) &&\n (content.mentions === undefined || features.mentions) &&\n (content.assets === undefined || features.assets) &&\n (content.replyToMessageKey === undefined || features.replies);\n\nconst checkDelivery = (\n features: AgentChannel.Features,\n command: Extract<AgentChannel.Command, { kind: \"deliver\" }>,\n): boolean =>\n checkMessage(features, command.destination, { text: \"\" }) &&\n (features.operations ?? []).includes(command.operation.kind);\n\nconst Material = Schema.Struct({\n connectionId: AgentChannel.Key,\n // The plugin worker's resolver marks its JSON-carried material.\n encoding: Schema.optionalKey(Schema.Literal(\"json\")),\n material: Schema.Unknown,\n methodId: AgentChannel.Key,\n providerId: AgentChannel.Key,\n setup: Schema.Unknown,\n});\nconst ResolveHook = Schema.declare(\n (value): value is (material: unknown, context: { readonly setup: unknown }) => unknown =>\n Predicate.isFunction(value),\n);\nconst resolveAuth = Effect.fn(\"AgentChannelRuntime.resolveAuth\")(function* (\n providerId: string,\n channelId: string,\n definition: AgentChannel.Definition,\n connectionId: string | undefined,\n phase: string,\n context: typeof ConnectionContext.Type | undefined,\n) {\n if (definition.authMethods.length === 0) {\n if (connectionId !== undefined) return yield* fail(\"invalid_auth\");\n return undefined;\n }\n // The host alone selects/authorizes the pinned connection. Its records never reach the plugin.\n if (connectionId === undefined) return yield* fail(\"invalid_auth\");\n const resolver = yield* Effect.serviceOption(ConnectionResolver.Service);\n if (Option.isNone(resolver)) return yield* fail(\"invalid_auth\");\n const raw = yield* safe(\n Effect.suspend(() =>\n resolver.value.resolve({\n connectionId,\n target: { phase, providerId, targetId: channelId, targetKind: \"agent-channel\" },\n ...(context === undefined ? {} : { context }),\n }),\n ),\n \"invalid_auth\",\n );\n const resolved = yield* decode(Material, raw, \"invalid_auth\");\n if (resolved.providerId !== providerId || resolved.connectionId !== connectionId) {\n return yield* fail(\"invalid_auth\");\n }\n const method = definition.authMethods.find(\n method =>\n resolved.methodId === method.identifier ||\n resolved.methodId === `${providerId}/${method.identifier}`,\n );\n if (method === undefined) return yield* fail(\"invalid_auth\");\n // Material the worker received as JSON decodes through each schema's JSON codec.\n const decodeAuth = <S extends Schema.Top>(schema: S, value: unknown) =>\n decode(\n resolved.encoding === \"json\" ? Schema.toCodecJson(schema) : schema,\n value,\n \"invalid_auth\",\n );\n const setup =\n method.setup === undefined\n ? yield* decode(Schema.Undefined, resolved.setup, \"invalid_auth\")\n : yield* decodeAuth(method.setup, resolved.setup);\n const material = yield* decodeAuth(method.material, resolved.material);\n let value: unknown;\n if (method.resolve === undefined) {\n value =\n method.material === method.value\n ? material\n : yield* decode(method.value, material, \"invalid_auth\");\n } else {\n const hook = yield* decode(ResolveHook, method.resolve, \"invalid_auth\");\n const output = yield* safe(\n Effect.suspend(() => {\n const result = hook(material, { setup });\n return Effect.isEffect(result) ? result : Effect.succeed(result);\n }),\n \"invalid_auth\",\n );\n value = yield* decode(method.value, output, \"invalid_auth\");\n }\n // Schemas may use Redacted for auth. Only this checked value, never material/setup/binding,\n // is exposed to the command handler.\n return { methodId: method.identifier, value };\n});\n\nconst find = (plugins: readonly Plugin.Any[], pin: Pin) => {\n for (const provider of plugins) {\n const channel = provider.agentChannels.find(\n channel => `${provider.identifier}/${channel.identifier}` === pin.channelId,\n );\n if (channel !== undefined) return { definition: channel.definition, provider };\n }\n return undefined;\n};\n\n/** Build from the installed plugins. */\nexport const layer = <P extends Plugin.Any>(\n plugins: readonly P[],\n): Layer.Layer<Service, never, Requirements<P>> =>\n Layer.effect(\n Service,\n Effect.gen(function* () {\n const context = yield* Effect.context<Requirements<P>>();\n const get = Effect.fn(\"AgentChannelRuntime.get\")(function* (input: unknown) {\n const pin = yield* decode(Pin, input, \"invalid_input\");\n const found = find(plugins, pin);\n if (found === undefined) return yield* fail(\"not_found\");\n yield* safe(\n Effect.sync(() => {\n AgentChannel.validateDefinition(\n found.definition,\n found.provider.identifier,\n found.provider.authMethods,\n );\n }),\n \"invalid_definition\",\n );\n const handler = Option.fromNullishOr(\n findHandler(\n context,\n found.provider.identifier,\n AgentChannel.handlerKey(pin.channelId),\n ) as AgentChannel.Handler | undefined,\n );\n if (\n Option.isNone(handler) ||\n !Predicate.isObject(handler.value.runtime) ||\n !Predicate.isFunction(handler.value.runtime.execute) ||\n !Predicate.isFunction(handler.value.runtime.verify) ||\n !Predicate.isFunction(handler.value.runtime.checkAccess)\n ) {\n return yield* fail(\"handler_unavailable\");\n }\n return found.definition;\n });\n const checkAccess = Effect.fn(\"AgentChannelRuntime.checkAccess\")(function* (input: unknown) {\n yield* json(input, \"invalid_input\");\n const request = yield* decode(AccessInput, input, \"invalid_input\");\n const definition = yield* get({ channelId: request.channelId });\n const found = find(plugins, request);\n if (found === undefined) return yield* fail(\"not_found\");\n const definitionSettings = yield* decodeData(\n definition.definitionSettings,\n request.definitionSettings,\n \"invalid_input\",\n );\n const deploymentSettings = yield* decodeData(\n definition.deploymentSettings,\n request.deploymentSettings,\n \"invalid_input\",\n );\n if (!checkMessage(definition.features, request.identity.conversation, { text: \"\" })) {\n return yield* fail(\"unsupported_feature\");\n }\n const auth = yield* resolveAuth(\n found.provider.identifier,\n request.channelId,\n definition,\n request.connectionId,\n \"check_access\",\n request.context,\n );\n const handler = Option.fromNullishOr(\n findHandler(\n context,\n found.provider.identifier,\n AgentChannel.handlerKey(request.channelId),\n ) as AgentChannel.Handler | undefined,\n );\n if (Option.isNone(handler)) return yield* fail(\"handler_unavailable\");\n const output = yield* invokeHandler(\n handler.value,\n Effect.suspend(() =>\n handler.value.runtime.checkAccess(request.identity, {\n definitionSettings,\n deploymentSettings,\n ...(auth === undefined ? {} : { auth }),\n }),\n ),\n );\n return yield* decodeData(AgentChannel.AccessOutcome, output, \"invalid_result\");\n });\n const execute = Effect.fn(\"AgentChannelRuntime.execute\")(function* (input: unknown) {\n yield* json(input, \"invalid_input\");\n const request = yield* decode(Input, input, \"invalid_input\");\n const definition = yield* get({ channelId: request.channelId });\n const found = find(plugins, request);\n if (found === undefined) return yield* fail(\"not_found\");\n const definitionSettings = yield* decodeData(\n definition.definitionSettings,\n request.definitionSettings,\n \"invalid_input\",\n );\n const deploymentSettings = yield* decodeData(\n definition.deploymentSettings,\n request.deploymentSettings,\n \"invalid_input\",\n );\n const command: AgentChannel.Command = yield* decodeData(\n AgentChannel.commandSchema(definition.state),\n request.command,\n \"invalid_input\",\n );\n yield* checkExtensions(definition, command.extensions, \"invalid_input\");\n if (command.kind === \"deliver\" && command.operationKey !== command.deliveryKey) {\n return yield* fail(\"invalid_input\");\n }\n if (command.kind === \"deliver\" && !checkDelivery(definition.features, command)) {\n return yield* fail(\"unsupported_feature\");\n }\n if (\n command.kind === \"deliver\" &&\n command.operation.kind === \"set_reaction\" &&\n command.operation.target.kind === \"activation\" &&\n command.activationMessageKey === undefined\n ) {\n return yield* fail(\"invalid_input\");\n }\n if (\n command.kind === \"read_context\" &&\n (definition.features.readContext !== true ||\n !checkMessage(definition.features, command.destination, { text: \"\" }))\n ) {\n return yield* fail(\"unsupported_feature\");\n }\n const handler = Option.fromNullishOr(\n findHandler(\n context,\n found.provider.identifier,\n AgentChannel.handlerKey(request.channelId),\n ) as AgentChannel.Handler | undefined,\n );\n if (Option.isNone(handler)) return yield* fail(\"handler_unavailable\");\n const auth = yield* resolveAuth(\n found.provider.identifier,\n request.channelId,\n definition,\n request.connectionId,\n command.kind,\n request.context,\n );\n // Keep correlation facts independent of any mutation by provider code.\n const operationKey = command.operationKey;\n const kind = command.kind;\n const deliveryKey = command.kind === \"deliver\" ? command.deliveryKey : undefined;\n const assetKey = command.kind === \"read_asset\" ? command.asset.assetKey : undefined;\n const adapterContext = {\n definitionSettings,\n deploymentSettings,\n ...(auth === undefined ? {} : { auth }),\n };\n if (\n !Predicate.isFunction(handler.value.runtime.execute) ||\n !Predicate.isFunction(handler.value.runtime.verify) ||\n !Predicate.isFunction(handler.value.runtime.checkAccess)\n ) {\n return yield* fail(\"handler_unavailable\");\n }\n if (command.kind === \"receive\") {\n yield* decodeData(\n AgentChannel.Verification,\n yield* invokeHandler(\n handler.value,\n Effect.suspend(() => handler.value.runtime.verify(command.request, adapterContext)),\n ),\n \"invalid_result\",\n );\n }\n if (command.kind === \"read_asset\") {\n if (!definition.features.assets) return yield* fail(\"unsupported_feature\");\n const decision = yield* decodeData(\n AgentChannel.AccessOutcome,\n yield* invokeHandler(\n handler.value,\n Effect.suspend(() =>\n handler.value.runtime.checkAccess(command.identity, adapterContext),\n ),\n ),\n \"invalid_result\",\n );\n if (decision.decision !== \"allow\") {\n return yield* new AgentChannel.ChannelError({\n code: \"provider_failure\",\n providerCode: \"unauthorized\",\n });\n }\n }\n const output = yield* invokeHandler(\n handler.value,\n Effect.suspend(() => handler.value.runtime.execute(command, adapterContext)),\n );\n const result: AgentChannel.Result = yield* decodeData(\n AgentChannel.resultSchema(Schema.toType(definition.state), definition.features),\n output,\n \"invalid_result\",\n kind === \"read_asset\",\n );\n if (\n result.kind !== kind ||\n result.operationKey !== operationKey ||\n (result.kind === \"deliver\" && result.deliveryKey !== deliveryKey) ||\n (result.kind === \"read_asset\" && result.assetKey !== assetKey)\n ) {\n return yield* fail(\"invalid_result\");\n }\n yield* checkExtensions(definition, result.extensions, \"invalid_result\");\n if (\n result.kind === \"deliver\" &&\n result.status === \"pending\" &&\n !definition.features.deliveryState\n ) {\n return yield* fail(\"invalid_result\");\n }\n const allowedEvents: AgentChannel.Event[] = [];\n const deniedEventKeys: string[] = [];\n if (result.kind === \"receive\") {\n if (result.deniedEventKeys !== undefined) return yield* fail(\"invalid_result\");\n if (\n result.activationProof === \"verified\" &&\n (result.response === undefined || result.events.length !== 0)\n ) {\n return yield* fail(\"invalid_result\");\n }\n const eventKeys = new Set<string>();\n for (const event of result.events) {\n if (eventKeys.has(event.eventKey)) return yield* fail(\"invalid_result\");\n eventKeys.add(event.eventKey);\n if (\n event.kind === \"message\" &&\n !checkMessage(definition.features, event.conversation, event.content)\n ) {\n return yield* fail(\"invalid_result\");\n }\n if (\n (event.kind === \"echo\" || event.kind === \"stop\") &&\n !checkMessage(definition.features, event.conversation, { text: \"\" })\n ) {\n return yield* fail(\"invalid_result\");\n }\n if (event.kind === \"delivery_update\" && !definition.features.deliveryState) {\n return yield* fail(\"invalid_result\");\n }\n yield* checkExtensions(definition, event.extensions, \"invalid_result\");\n let denied = false;\n if (event.kind === \"message\" || event.kind === \"echo\" || event.kind === \"stop\") {\n const identity = yield* decodeData(\n AgentChannel.VerifiedIdentity,\n { conversation: event.conversation, senderKey: event.senderKey },\n \"invalid_result\",\n );\n const decision = yield* decodeData(\n AgentChannel.AccessOutcome,\n yield* invokeHandler(\n handler.value,\n Effect.suspend(() => handler.value.runtime.checkAccess(identity, adapterContext)),\n ),\n \"invalid_result\",\n );\n denied = decision.decision === \"deny\";\n }\n if (denied) {\n deniedEventKeys.push(event.eventKey);\n continue;\n }\n allowedEvents.push(event);\n }\n }\n // Store the encoded state so subsequent pinned commands can decode it exactly once.\n const encoded = yield* safe(\n Schema.encodeUnknownEffect(\n AgentChannel.resultSchema(definition.state, definition.features),\n )(\n result.kind === \"receive\"\n ? {\n ...result,\n events: allowedEvents,\n ...(deniedEventKeys.length === 0 ? {} : { deniedEventKeys }),\n }\n : result,\n strict,\n ),\n \"invalid_result\",\n );\n return yield* decodeData(\n AgentChannel.CheckedResult,\n encoded,\n \"invalid_result\",\n kind === \"read_asset\",\n );\n });\n // SAFETY: Requirements above account for each schema, auth method and Channel handler. The\n // dynamic lookup erases their union; the captured application context discharges it here.\n const run = <A>(\n effect: Effect.Effect<A, AgentChannel.ChannelError, unknown>,\n ): Effect.Effect<A, AgentChannel.ChannelError> =>\n // @effect-diagnostics-next-line unsafeEffectTypeAssertion:off -- Channel handlers are checked and their captured context satisfies the declared Requirements (SAFETY above).\n effect.pipe(Effect.provideContext(context)) as Effect.Effect<A, AgentChannel.ChannelError>;\n const decodeSettings = (field: \"definitionSettings\" | \"deploymentSettings\") =>\n Effect.fn(\"AgentChannelRuntime.decodeSettings\")(function* (input: unknown) {\n const request = yield* decode(\n Schema.Struct({ ...Pin.fields, value: Schema.Json }),\n input,\n \"invalid_input\",\n );\n const definition = yield* get({ channelId: request.channelId });\n const schema = definition[field];\n const value = yield* decodeData(schema, request.value, \"invalid_input\");\n return yield* json(\n yield* safe(Schema.encodeUnknownEffect(schema)(value, strict), \"invalid_input\"),\n \"invalid_input\",\n );\n });\n return Service.of({\n checkAccess: input => run(checkAccess(input)),\n decodeDefinitionSettings: input => run(decodeSettings(\"definitionSettings\")(input)),\n decodeDeploymentSettings: input => run(decodeSettings(\"deploymentSettings\")(input)),\n execute: input => run(execute(input)),\n get: input => run(get(input)),\n });\n }),\n );\n\nexport * as AgentChannelRuntime from \"./AgentChannelRuntime.ts\";\n"],"mappings":";;;;;;;;;;;;;;;AAUA,MAAa,oBAAoB,OAAO,OAAO;CAC7C,OAAO,OAAO,YACZ,OAAO,MAAM,CACX,OAAO,OAAO;EAAE,MAAM,OAAO,QAAQ,MAAM;EAAG,QAAQA;CAAiB,CAAC,GACxE,OAAO,OAAO;EACZ,MAAM,OAAO,QAAQ,QAAQ;EAC7B,QAAQ,OAAO,YAAYA,GAAgB;CAC7C,CAAC,CACH,CAAC,CACH;CACA,QAAQ,OAAO,YACb,OAAO,OAAO;EAAE,MAAMA;EAAkB,WAAW,OAAO,YAAYA,GAAgB;CAAE,CAAC,CAC3F;CACA,QAAQ,OAAO,YACb,OAAO,OAAO;EAAE,gBAAgBA;EAAkB,QAAQA;CAAiB,CAAC,CAC9E;AACF,CAAC;AACD,MAAM,MAAM,OAAO,OAAO,EAAE,WAAWA,IAAiB,CAAC;AACzD,MAAM,QAAQ,OAAO,OAAO;CAC1B,GAAG,IAAI;CACP,SAAS,OAAO;CAChB,cAAc,OAAO,YAAYA,GAAgB;CACjD,SAAS,OAAO,YAAY,iBAAiB;CAC7C,oBAAoB,OAAO;CAC3B,oBAAoB,OAAO;AAC7B,CAAC;AACD,MAAM,cAAc,OAAO,OAAO;CAChC,GAAG,IAAI;CACP,cAAc,OAAO,YAAYA,GAAgB;CACjD,SAAS,OAAO,YAAY,iBAAiB;CAC7C,oBAAoB,OAAO;CAC3B,oBAAoB,OAAO;CAC3B,UAAUC;AACZ,CAAC;AAmBD,IAAa,UAAb,cAA6B,QAAQ,QAA4B,CAAC,CAChE,kCACF,CAAC,CAAC,CAAC;AA0BH,MAAM,QAAQ,SAA6C,IAAIC,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Schema.Struct({
|
|
|
36
36
|
/** Maximum Unicode code points per physical text message, including server-added prefixes. */
|
|
37
37
|
maxTextLength: Schema.optionalKey(Schema.Int.check(Schema.isGreaterThan(0))),
|
|
38
38
|
mentions: Schema.Boolean,
|
|
39
|
-
/**
|
|
39
|
+
/**
|
|
40
|
+
* The output operations every destination of this version shows. Every definition declares
|
|
41
|
+
* them; retired catalog contracts that predate them still decode.
|
|
42
|
+
*/
|
|
40
43
|
operations: Schema.optionalKey(Schema.Array(OperationKind)),
|
|
41
44
|
/** Whether `read_context` returns the conversation's earlier messages. */
|
|
42
45
|
readContext: Schema.optionalKey(Schema.Boolean),
|
|
@@ -285,8 +288,7 @@ export const Operation = Schema.Union([
|
|
|
285
288
|
}),
|
|
286
289
|
]);
|
|
287
290
|
export type Operation = typeof Operation.Type;
|
|
288
|
-
|
|
289
|
-
export const ContextMessage = Schema.Struct({
|
|
291
|
+
const contextMessageFields = {
|
|
290
292
|
messageKey: Key,
|
|
291
293
|
/** The agent's own message. */
|
|
292
294
|
own: Schema.Boolean,
|
|
@@ -294,8 +296,16 @@ export const ContextMessage = Schema.Struct({
|
|
|
294
296
|
senderName: Schema.optionalKey(Schema.NonEmptyString.check(Schema.isMaxLength(256))),
|
|
295
297
|
text: Text,
|
|
296
298
|
timestamp: Timestamp,
|
|
299
|
+
};
|
|
300
|
+
/** Published contracts of versions without both `assets` and `readContext` keep this shape. */
|
|
301
|
+
const TextContextMessage = Schema.Struct(contextMessageFields);
|
|
302
|
+
/** A message read back from history; `assets` only where a version declares assets and context. */
|
|
303
|
+
export const ContextMessage = Schema.Struct({
|
|
304
|
+
...contextMessageFields,
|
|
305
|
+
assets: Schema.optionalKey(Schema.Array(Asset).check(Schema.isMaxLength(20))),
|
|
297
306
|
});
|
|
298
307
|
export type ContextMessage = typeof ContextMessage.Type;
|
|
308
|
+
|
|
299
309
|
/** Decoded originals are limited separately by the host; ordinary command JSON stays bounded. */
|
|
300
310
|
export const AssetFile = ToolFile.Schema.check(
|
|
301
311
|
Schema.makeFilter(
|
|
@@ -369,7 +379,7 @@ const installedCommandSchema = <State extends Schema.Top>(state: State) => {
|
|
|
369
379
|
]);
|
|
370
380
|
};
|
|
371
381
|
|
|
372
|
-
const installedResultSchema = <State extends Schema.Top>(state: State) => {
|
|
382
|
+
const installedResultSchema = <State extends Schema.Top>(state: State, features?: Features) => {
|
|
373
383
|
const operation = { extensions: Schema.optionalKey(Extensions), operationKey: Key };
|
|
374
384
|
return Schema.Union([
|
|
375
385
|
Schema.Struct({
|
|
@@ -423,7 +433,12 @@ const installedResultSchema = <State extends Schema.Top>(state: State) => {
|
|
|
423
433
|
Schema.Struct({
|
|
424
434
|
kind: Schema.Literal("read_context"),
|
|
425
435
|
...operation,
|
|
426
|
-
|
|
436
|
+
// Without a version's features, any checked result: the host reads every version's.
|
|
437
|
+
messages: Schema.Array(
|
|
438
|
+
features === undefined || (features.assets && features.readContext === true)
|
|
439
|
+
? ContextMessage
|
|
440
|
+
: TextContextMessage,
|
|
441
|
+
).check(Schema.isMaxLength(200)),
|
|
427
442
|
}),
|
|
428
443
|
]);
|
|
429
444
|
};
|
|
@@ -446,8 +461,9 @@ const readAssetResult = Schema.Struct({
|
|
|
446
461
|
});
|
|
447
462
|
export const commandSchema = <State extends Schema.Top>(state: State) =>
|
|
448
463
|
Schema.Union([installedCommandSchema(state), readAssetCommand(state)]);
|
|
449
|
-
|
|
450
|
-
|
|
464
|
+
/** Pass a version's features to check its results against its own contract. */
|
|
465
|
+
export const resultSchema = <State extends Schema.Top>(state: State, features?: Features) =>
|
|
466
|
+
Schema.Union([installedResultSchema(state, features), readAssetResult]);
|
|
451
467
|
export type Command<State extends Schema.Top = Schema.Unknown> = ReturnType<
|
|
452
468
|
typeof commandSchema<State>
|
|
453
469
|
>["Type"];
|
|
@@ -528,7 +544,7 @@ export const projectContract = (
|
|
|
528
544
|
),
|
|
529
545
|
featuresJson: definition.features,
|
|
530
546
|
operationInputSchemaJson: project(commandSchema(definition.state)),
|
|
531
|
-
operationOutputSchemaJson: project(resultSchema(definition.state)),
|
|
547
|
+
operationOutputSchemaJson: project(resultSchema(definition.state, definition.features)),
|
|
532
548
|
requiredChecks: definition.requiredChecks,
|
|
533
549
|
stateSchemaJson: project(definition.state),
|
|
534
550
|
},
|
|
@@ -482,7 +482,7 @@ export const layer = <P extends Plugin.Any>(
|
|
|
482
482
|
Effect.suspend(() => handler.value.runtime.execute(command, adapterContext)),
|
|
483
483
|
);
|
|
484
484
|
const result: AgentChannel.Result = yield* decodeData(
|
|
485
|
-
AgentChannel.resultSchema(Schema.toType(definition.state)),
|
|
485
|
+
AgentChannel.resultSchema(Schema.toType(definition.state), definition.features),
|
|
486
486
|
output,
|
|
487
487
|
"invalid_result",
|
|
488
488
|
kind === "read_asset",
|
|
@@ -559,7 +559,9 @@ export const layer = <P extends Plugin.Any>(
|
|
|
559
559
|
}
|
|
560
560
|
// Store the encoded state so subsequent pinned commands can decode it exactly once.
|
|
561
561
|
const encoded = yield* safe(
|
|
562
|
-
Schema.encodeUnknownEffect(
|
|
562
|
+
Schema.encodeUnknownEffect(
|
|
563
|
+
AgentChannel.resultSchema(definition.state, definition.features),
|
|
564
|
+
)(
|
|
563
565
|
result.kind === "receive"
|
|
564
566
|
? {
|
|
565
567
|
...result,
|