@xemahq/agent-session-runtime 0.6.7 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/README.md +6 -1
  2. package/dist/index.d.ts +1 -0
  3. package/dist/index.d.ts.map +1 -1
  4. package/dist/index.js +1 -0
  5. package/dist/index.js.map +1 -1
  6. package/dist/lib/dispatch-contract.d.ts +2 -1
  7. package/dist/lib/dispatch-contract.d.ts.map +1 -1
  8. package/dist/lib/launch-identity/canonical-contract.d.ts +21 -0
  9. package/dist/lib/launch-identity/canonical-contract.d.ts.map +1 -0
  10. package/dist/lib/launch-identity/canonical-contract.js +217 -0
  11. package/dist/lib/launch-identity/canonical-contract.js.map +1 -0
  12. package/dist/lib/launch-identity/compiled-session-launch-plan-store.d.ts +44 -0
  13. package/dist/lib/launch-identity/compiled-session-launch-plan-store.d.ts.map +1 -0
  14. package/dist/lib/launch-identity/compiled-session-launch-plan-store.js +116 -0
  15. package/dist/lib/launch-identity/compiled-session-launch-plan-store.js.map +1 -0
  16. package/dist/lib/launch-identity/compiled-session-launch-plan.d.ts +84 -0
  17. package/dist/lib/launch-identity/compiled-session-launch-plan.d.ts.map +1 -0
  18. package/dist/lib/launch-identity/compiled-session-launch-plan.js +386 -0
  19. package/dist/lib/launch-identity/compiled-session-launch-plan.js.map +1 -0
  20. package/dist/lib/launch-identity/index.d.ts +7 -0
  21. package/dist/lib/launch-identity/index.d.ts.map +1 -0
  22. package/dist/lib/launch-identity/index.js +23 -0
  23. package/dist/lib/launch-identity/index.js.map +1 -0
  24. package/dist/lib/launch-identity/runtime-template-key.d.ts +30 -0
  25. package/dist/lib/launch-identity/runtime-template-key.d.ts.map +1 -0
  26. package/dist/lib/launch-identity/runtime-template-key.js +73 -0
  27. package/dist/lib/launch-identity/runtime-template-key.js.map +1 -0
  28. package/dist/lib/launch-identity/session-binding.d.ts +24 -0
  29. package/dist/lib/launch-identity/session-binding.d.ts.map +1 -0
  30. package/dist/lib/launch-identity/session-binding.js +62 -0
  31. package/dist/lib/launch-identity/session-binding.js.map +1 -0
  32. package/dist/lib/launch-identity/thread-reuse-key.d.ts +19 -0
  33. package/dist/lib/launch-identity/thread-reuse-key.d.ts.map +1 -0
  34. package/dist/lib/launch-identity/thread-reuse-key.js +46 -0
  35. package/dist/lib/launch-identity/thread-reuse-key.js.map +1 -0
  36. package/package.json +4 -3
  37. package/src/index.ts +1 -0
  38. package/src/lib/dispatch-contract.ts +4 -9
  39. package/src/lib/launch-identity/canonical-contract.ts +318 -0
  40. package/src/lib/launch-identity/compiled-session-launch-plan-store.ts +178 -0
  41. package/src/lib/launch-identity/compiled-session-launch-plan.ts +689 -0
  42. package/src/lib/launch-identity/index.ts +6 -0
  43. package/src/lib/launch-identity/runtime-template-key.ts +148 -0
  44. package/src/lib/launch-identity/session-binding.ts +152 -0
  45. package/src/lib/launch-identity/thread-reuse-key.ts +93 -0
  46. package/dist/lib/composition-resolution.d.ts +0 -43
  47. package/dist/lib/composition-resolution.d.ts.map +0 -1
  48. package/dist/lib/composition-resolution.js +0 -236
  49. package/dist/lib/composition-resolution.js.map +0 -1
  50. package/dist/lib/composition-workspace-manifest.d.ts +0 -51
  51. package/dist/lib/composition-workspace-manifest.d.ts.map +0 -1
  52. package/dist/lib/composition-workspace-manifest.js +0 -178
  53. package/dist/lib/composition-workspace-manifest.js.map +0 -1
@@ -0,0 +1,148 @@
1
+ import {
2
+ assertNoTenantOrSecretTemplateFields,
3
+ canonicalContractJson,
4
+ hashCanonicalContract,
5
+ requireEnumValue,
6
+ requireExactObject,
7
+ requireNonEmptyString,
8
+ requireSha256,
9
+ } from './canonical-contract';
10
+
11
+ export enum RuntimeTemplateTenantDependency {
12
+ OrganizationNeutral = 'organization-neutral',
13
+ OrganizationBound = 'organization-bound',
14
+ }
15
+
16
+ export enum RuntimeTemplateTrustPolicy {
17
+ Shared = 'shared',
18
+ Dedicated = 'dedicated',
19
+ Confidential = 'confidential',
20
+ }
21
+
22
+ export interface RuntimeTemplateKey {
23
+ readonly schemaVersion: 1;
24
+ readonly tenantDependency: RuntimeTemplateTenantDependency;
25
+ readonly trustPolicy: RuntimeTemplateTrustPolicy;
26
+ readonly runtimeRef: string;
27
+ readonly runtimeRevision: string;
28
+ readonly imageDigest: string;
29
+ readonly agentRevision: string;
30
+ readonly primaryAgentHash: string;
31
+ readonly subagentsHash: string;
32
+ readonly skillsHash: string;
33
+ readonly toolsHash: string;
34
+ readonly capabilityDescriptorsHash: string;
35
+ readonly mcpDescriptorsHash: string;
36
+ readonly workspacePlanHash: string;
37
+ readonly layoutProfile: string;
38
+ }
39
+
40
+ const REQUIRED_KEYS = [
41
+ 'schemaVersion',
42
+ 'tenantDependency',
43
+ 'trustPolicy',
44
+ 'runtimeRef',
45
+ 'runtimeRevision',
46
+ 'imageDigest',
47
+ 'agentRevision',
48
+ 'primaryAgentHash',
49
+ 'subagentsHash',
50
+ 'skillsHash',
51
+ 'toolsHash',
52
+ 'capabilityDescriptorsHash',
53
+ 'mcpDescriptorsHash',
54
+ 'workspacePlanHash',
55
+ 'layoutProfile',
56
+ ] as const;
57
+
58
+ const TENANT_DEPENDENCIES = Object.values(RuntimeTemplateTenantDependency);
59
+ const TRUST_POLICIES = Object.values(RuntimeTemplateTrustPolicy);
60
+ const IMAGE_DIGEST_PATTERN = /^sha256:[a-f0-9]{64}$/u;
61
+
62
+ /**
63
+ * Validates and canonicalizes the immutable execution dimensions used to
64
+ * select warm compute. Tenant, invocation and credential data have no valid
65
+ * slot in this contract and are rejected even when supplied as extra fields.
66
+ */
67
+ export function createRuntimeTemplateKey(input: unknown): RuntimeTemplateKey {
68
+ assertNoTenantOrSecretTemplateFields(input, 'RuntimeTemplateKey');
69
+ const object = requireExactObject(input, 'RuntimeTemplateKey', REQUIRED_KEYS);
70
+
71
+ if (object.schemaVersion !== 1) {
72
+ throw new TypeError('RuntimeTemplateKey.schemaVersion must be 1.');
73
+ }
74
+
75
+ const imageDigest = requireNonEmptyString(
76
+ object.imageDigest,
77
+ 'RuntimeTemplateKey.imageDigest',
78
+ );
79
+ if (!IMAGE_DIGEST_PATTERN.test(imageDigest)) {
80
+ throw new TypeError(
81
+ 'RuntimeTemplateKey.imageDigest must be an immutable sha256 image digest.',
82
+ );
83
+ }
84
+
85
+ return Object.freeze({
86
+ schemaVersion: 1,
87
+ tenantDependency: requireEnumValue(
88
+ object.tenantDependency,
89
+ 'RuntimeTemplateKey.tenantDependency',
90
+ TENANT_DEPENDENCIES,
91
+ ),
92
+ trustPolicy: requireEnumValue(
93
+ object.trustPolicy,
94
+ 'RuntimeTemplateKey.trustPolicy',
95
+ TRUST_POLICIES,
96
+ ),
97
+ runtimeRef: requireNonEmptyString(
98
+ object.runtimeRef,
99
+ 'RuntimeTemplateKey.runtimeRef',
100
+ ),
101
+ runtimeRevision: requireNonEmptyString(
102
+ object.runtimeRevision,
103
+ 'RuntimeTemplateKey.runtimeRevision',
104
+ ),
105
+ imageDigest,
106
+ agentRevision: requireNonEmptyString(
107
+ object.agentRevision,
108
+ 'RuntimeTemplateKey.agentRevision',
109
+ ),
110
+ primaryAgentHash: requireSha256(
111
+ object.primaryAgentHash,
112
+ 'RuntimeTemplateKey.primaryAgentHash',
113
+ ),
114
+ subagentsHash: requireSha256(
115
+ object.subagentsHash,
116
+ 'RuntimeTemplateKey.subagentsHash',
117
+ ),
118
+ skillsHash: requireSha256(
119
+ object.skillsHash,
120
+ 'RuntimeTemplateKey.skillsHash',
121
+ ),
122
+ toolsHash: requireSha256(object.toolsHash, 'RuntimeTemplateKey.toolsHash'),
123
+ capabilityDescriptorsHash: requireSha256(
124
+ object.capabilityDescriptorsHash,
125
+ 'RuntimeTemplateKey.capabilityDescriptorsHash',
126
+ ),
127
+ mcpDescriptorsHash: requireSha256(
128
+ object.mcpDescriptorsHash,
129
+ 'RuntimeTemplateKey.mcpDescriptorsHash',
130
+ ),
131
+ workspacePlanHash: requireSha256(
132
+ object.workspacePlanHash,
133
+ 'RuntimeTemplateKey.workspacePlanHash',
134
+ ),
135
+ layoutProfile: requireNonEmptyString(
136
+ object.layoutProfile,
137
+ 'RuntimeTemplateKey.layoutProfile',
138
+ ),
139
+ });
140
+ }
141
+
142
+ export function serializeRuntimeTemplateKey(input: RuntimeTemplateKey): string {
143
+ return canonicalContractJson(createRuntimeTemplateKey(input));
144
+ }
145
+
146
+ export function hashRuntimeTemplateKey(input: RuntimeTemplateKey): string {
147
+ return hashCanonicalContract(createRuntimeTemplateKey(input));
148
+ }
@@ -0,0 +1,152 @@
1
+ import {
2
+ canonicalContractJson,
3
+ type CanonicalJsonValue,
4
+ hashCanonicalContract,
5
+ type ResourceBindingRef,
6
+ requireExactObject,
7
+ requireNonEmptyString,
8
+ requireNonNegativeSafeInteger,
9
+ requireResourceBindingRefs,
10
+ requireSecretFreeJsonObject,
11
+ requireStringRefs,
12
+ } from './canonical-contract';
13
+
14
+ export interface SessionBinding {
15
+ readonly schemaVersion: 1;
16
+ readonly sessionId: string;
17
+ readonly organizationId: string;
18
+ readonly projectId: string;
19
+ readonly userId: string;
20
+ readonly domainRefs: readonly ResourceBindingRef[];
21
+ readonly storageAllocationRef: string;
22
+ readonly workingFileSourceRefs: readonly string[];
23
+ readonly outputRouteRef: string;
24
+ readonly actorTokenRef?: string;
25
+ readonly serviceTokenRef?: string;
26
+ readonly providerTokenRefs: readonly string[];
27
+ readonly credentialGrantRefs: readonly string[];
28
+ readonly databaseGrantRefs: readonly string[];
29
+ readonly dynamicContext: Readonly<Record<string, CanonicalJsonValue>>;
30
+ readonly bindingRevision: string;
31
+ readonly bindingEpoch: number;
32
+ }
33
+
34
+ const REQUIRED_KEYS = [
35
+ 'schemaVersion',
36
+ 'sessionId',
37
+ 'organizationId',
38
+ 'projectId',
39
+ 'userId',
40
+ 'domainRefs',
41
+ 'storageAllocationRef',
42
+ 'workingFileSourceRefs',
43
+ 'outputRouteRef',
44
+ 'providerTokenRefs',
45
+ 'credentialGrantRefs',
46
+ 'databaseGrantRefs',
47
+ 'dynamicContext',
48
+ 'bindingRevision',
49
+ 'bindingEpoch',
50
+ ] as const;
51
+
52
+ const OPTIONAL_KEYS = ['actorTokenRef', 'serviceTokenRef'] as const;
53
+
54
+ /**
55
+ * Canonical tenant/session state applied atomically after a runtime claim.
56
+ * Credentials are represented only by opaque refs; raw secrets are rejected
57
+ * from dynamicContext.
58
+ */
59
+ export function createSessionBinding(input: unknown): SessionBinding {
60
+ const object = requireExactObject(
61
+ input,
62
+ 'SessionBinding',
63
+ REQUIRED_KEYS,
64
+ OPTIONAL_KEYS,
65
+ );
66
+
67
+ if (object.schemaVersion !== 1) {
68
+ throw new TypeError('SessionBinding.schemaVersion must be 1.');
69
+ }
70
+
71
+ const actorTokenRef =
72
+ object.actorTokenRef === undefined
73
+ ? undefined
74
+ : requireNonEmptyString(
75
+ object.actorTokenRef,
76
+ 'SessionBinding.actorTokenRef',
77
+ );
78
+ const serviceTokenRef =
79
+ object.serviceTokenRef === undefined
80
+ ? undefined
81
+ : requireNonEmptyString(
82
+ object.serviceTokenRef,
83
+ 'SessionBinding.serviceTokenRef',
84
+ );
85
+
86
+ return Object.freeze({
87
+ schemaVersion: 1,
88
+ sessionId: requireNonEmptyString(
89
+ object.sessionId,
90
+ 'SessionBinding.sessionId',
91
+ ),
92
+ organizationId: requireNonEmptyString(
93
+ object.organizationId,
94
+ 'SessionBinding.organizationId',
95
+ ),
96
+ projectId: requireNonEmptyString(
97
+ object.projectId,
98
+ 'SessionBinding.projectId',
99
+ ),
100
+ userId: requireNonEmptyString(object.userId, 'SessionBinding.userId'),
101
+ domainRefs: requireResourceBindingRefs(
102
+ object.domainRefs,
103
+ 'SessionBinding.domainRefs',
104
+ ),
105
+ storageAllocationRef: requireNonEmptyString(
106
+ object.storageAllocationRef,
107
+ 'SessionBinding.storageAllocationRef',
108
+ ),
109
+ workingFileSourceRefs: requireStringRefs(
110
+ object.workingFileSourceRefs,
111
+ 'SessionBinding.workingFileSourceRefs',
112
+ ),
113
+ outputRouteRef: requireNonEmptyString(
114
+ object.outputRouteRef,
115
+ 'SessionBinding.outputRouteRef',
116
+ ),
117
+ ...(actorTokenRef === undefined ? {} : { actorTokenRef }),
118
+ ...(serviceTokenRef === undefined ? {} : { serviceTokenRef }),
119
+ providerTokenRefs: requireStringRefs(
120
+ object.providerTokenRefs,
121
+ 'SessionBinding.providerTokenRefs',
122
+ ),
123
+ credentialGrantRefs: requireStringRefs(
124
+ object.credentialGrantRefs,
125
+ 'SessionBinding.credentialGrantRefs',
126
+ ),
127
+ databaseGrantRefs: requireStringRefs(
128
+ object.databaseGrantRefs,
129
+ 'SessionBinding.databaseGrantRefs',
130
+ ),
131
+ dynamicContext: requireSecretFreeJsonObject(
132
+ object.dynamicContext,
133
+ 'SessionBinding.dynamicContext',
134
+ ),
135
+ bindingRevision: requireNonEmptyString(
136
+ object.bindingRevision,
137
+ 'SessionBinding.bindingRevision',
138
+ ),
139
+ bindingEpoch: requireNonNegativeSafeInteger(
140
+ object.bindingEpoch,
141
+ 'SessionBinding.bindingEpoch',
142
+ ),
143
+ });
144
+ }
145
+
146
+ export function serializeSessionBinding(input: SessionBinding): string {
147
+ return canonicalContractJson(createSessionBinding(input));
148
+ }
149
+
150
+ export function hashSessionBinding(input: SessionBinding): string {
151
+ return hashCanonicalContract(createSessionBinding(input));
152
+ }
@@ -0,0 +1,93 @@
1
+ import {
2
+ canonicalContractJson,
3
+ hashCanonicalContract,
4
+ type ResourceBindingRef,
5
+ requireEnumValue,
6
+ requireExactObject,
7
+ requireNonEmptyString,
8
+ requireResourceBindingRefs,
9
+ requireSha256,
10
+ } from './canonical-contract';
11
+
12
+ export enum ThreadReusePolicy {
13
+ ExplicitlyShareable = 'explicitly-shareable',
14
+ }
15
+
16
+ export interface ThreadReuseKey {
17
+ readonly schemaVersion: 1;
18
+ readonly reusePolicy: ThreadReusePolicy.ExplicitlyShareable;
19
+ readonly organizationId: string;
20
+ readonly projectId: string;
21
+ readonly userId: string;
22
+ readonly runtimeTemplateHash: string;
23
+ readonly conversationRef: string;
24
+ readonly workspaceRef: string;
25
+ readonly domainRefs: readonly ResourceBindingRef[];
26
+ }
27
+
28
+ const REQUIRED_KEYS = [
29
+ 'schemaVersion',
30
+ 'reusePolicy',
31
+ 'organizationId',
32
+ 'projectId',
33
+ 'userId',
34
+ 'runtimeTemplateHash',
35
+ 'conversationRef',
36
+ 'workspaceRef',
37
+ 'domainRefs',
38
+ ] as const;
39
+
40
+ /**
41
+ * Canonical identity for the deliberately narrower same-user conversation and
42
+ * filesystem reuse decision. A RuntimeTemplateKey match alone never permits
43
+ * Thread reuse.
44
+ */
45
+ export function createThreadReuseKey(input: unknown): ThreadReuseKey {
46
+ const object = requireExactObject(input, 'ThreadReuseKey', REQUIRED_KEYS);
47
+
48
+ if (object.schemaVersion !== 1) {
49
+ throw new TypeError('ThreadReuseKey.schemaVersion must be 1.');
50
+ }
51
+
52
+ return Object.freeze({
53
+ schemaVersion: 1,
54
+ reusePolicy: requireEnumValue(
55
+ object.reusePolicy,
56
+ 'ThreadReuseKey.reusePolicy',
57
+ [ThreadReusePolicy.ExplicitlyShareable],
58
+ ),
59
+ organizationId: requireNonEmptyString(
60
+ object.organizationId,
61
+ 'ThreadReuseKey.organizationId',
62
+ ),
63
+ projectId: requireNonEmptyString(
64
+ object.projectId,
65
+ 'ThreadReuseKey.projectId',
66
+ ),
67
+ userId: requireNonEmptyString(object.userId, 'ThreadReuseKey.userId'),
68
+ runtimeTemplateHash: requireSha256(
69
+ object.runtimeTemplateHash,
70
+ 'ThreadReuseKey.runtimeTemplateHash',
71
+ ),
72
+ conversationRef: requireNonEmptyString(
73
+ object.conversationRef,
74
+ 'ThreadReuseKey.conversationRef',
75
+ ),
76
+ workspaceRef: requireNonEmptyString(
77
+ object.workspaceRef,
78
+ 'ThreadReuseKey.workspaceRef',
79
+ ),
80
+ domainRefs: requireResourceBindingRefs(
81
+ object.domainRefs,
82
+ 'ThreadReuseKey.domainRefs',
83
+ ),
84
+ });
85
+ }
86
+
87
+ export function serializeThreadReuseKey(input: ThreadReuseKey): string {
88
+ return canonicalContractJson(createThreadReuseKey(input));
89
+ }
90
+
91
+ export function hashThreadReuseKey(input: ThreadReuseKey): string {
92
+ return hashCanonicalContract(createThreadReuseKey(input));
93
+ }
@@ -1,43 +0,0 @@
1
- import { type ModelRef, type NodeOverlayFragment, type SubAgentBinding } from '@xemahq/kernel-contracts/workflow';
2
- import type { ResolvedAgent, ResolvedAgentNode } from '@xemahq/kernel-contracts/agent-composition';
3
- import type { PermissionMap } from '@xemahq/kernel-contracts/agent-permission';
4
- import { type ToolSelectionEntry } from '@xemahq/kernel-contracts/mcp-tool';
5
- export declare class AgentResolutionError extends Error {
6
- constructor(context: string, detail: string);
7
- }
8
- export interface FlattenedAgentNode {
9
- readonly slug: string;
10
- readonly alias?: string;
11
- readonly modelOverride?: ModelRef;
12
- readonly instructions?: string;
13
- readonly permission?: PermissionMap;
14
- }
15
- export interface CollectScopeOptions {
16
- readonly scope?: 'tree' | 'root';
17
- }
18
- export interface RuntimeAgentConfig {
19
- readonly agentRef: string;
20
- readonly primaryAgentSlug: string;
21
- readonly primaryInstructions: string | null;
22
- readonly primaryPermission: PermissionMap | null;
23
- readonly primaryModelOverride: ModelRef | null;
24
- readonly subAgentBindings: readonly SubAgentBinding[];
25
- readonly subAgentInstructionsBySlug: Readonly<Record<string, string>>;
26
- readonly subAgentPermissionBySlug: Readonly<Record<string, PermissionMap>>;
27
- readonly subAgentModelOverridesBySlug: Readonly<Record<string, ModelRef>>;
28
- readonly defaultSkillSlugs: readonly string[];
29
- readonly allSkillSlugs: readonly string[];
30
- readonly defaultToolSelection: readonly ToolSelectionEntry[];
31
- }
32
- export declare function flattenAgentTree(root: ResolvedAgentNode): readonly FlattenedAgentNode[];
33
- export declare function collectSkills(root: ResolvedAgentNode, opts?: CollectScopeOptions): readonly string[];
34
- export declare function collectTools(root: ResolvedAgentNode, opts?: CollectScopeOptions): readonly ToolSelectionEntry[];
35
- export declare function collectInstructionsBySlug(root: ResolvedAgentNode): Readonly<Record<string, string>>;
36
- export declare function collectPermissionsBySlug(root: ResolvedAgentNode): Readonly<Record<string, PermissionMap>>;
37
- export declare function collectModelOverridesBySlug(root: ResolvedAgentNode): Readonly<Record<string, ModelRef>>;
38
- export declare function appendInstructions(baseSystemPrompt: string, nodeInstructions: string | null): string;
39
- export declare function normalizeInstructions(raw: string | undefined): string | null;
40
- export declare function normalizePermission(raw: PermissionMap | undefined): PermissionMap | null;
41
- export declare function projectModelOverride(raw: ModelRef | undefined, context: string): ModelRef | null;
42
- export declare function projectAgentToRuntimeConfig(resolved: ResolvedAgent, overlay?: NodeOverlayFragment): RuntimeAgentConfig;
43
- //# sourceMappingURL=composition-resolution.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"composition-resolution.d.ts","sourceRoot":"","sources":["../../src/lib/composition-resolution.ts"],"names":[],"mappings":"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"}
@@ -1,236 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AgentResolutionError = void 0;
4
- exports.flattenAgentTree = flattenAgentTree;
5
- exports.collectSkills = collectSkills;
6
- exports.collectTools = collectTools;
7
- exports.collectInstructionsBySlug = collectInstructionsBySlug;
8
- exports.collectPermissionsBySlug = collectPermissionsBySlug;
9
- exports.collectModelOverridesBySlug = collectModelOverridesBySlug;
10
- exports.appendInstructions = appendInstructions;
11
- exports.normalizeInstructions = normalizeInstructions;
12
- exports.normalizePermission = normalizePermission;
13
- exports.projectModelOverride = projectModelOverride;
14
- exports.projectAgentToRuntimeConfig = projectAgentToRuntimeConfig;
15
- const workflow_1 = require("@xemahq/kernel-contracts/workflow");
16
- const mcp_tool_1 = require("@xemahq/kernel-contracts/mcp-tool");
17
- class AgentResolutionError extends Error {
18
- constructor(context, detail) {
19
- super(`Agent resolution failed for "${context}": ${detail}`);
20
- this.name = 'AgentResolutionError';
21
- }
22
- }
23
- exports.AgentResolutionError = AgentResolutionError;
24
- function flattenAgentTree(root) {
25
- const seen = new Set();
26
- const out = [];
27
- const visit = (node) => {
28
- for (const child of node.children) {
29
- const slug = child.kernel.slug;
30
- if (slug.length === 0) {
31
- continue;
32
- }
33
- if (!seen.has(slug)) {
34
- seen.add(slug);
35
- out.push({
36
- slug,
37
- ...(child.alias ? { alias: child.alias } : {}),
38
- ...(child.modelOverride
39
- ? { modelOverride: child.modelOverride }
40
- : {}),
41
- ...(child.instructions ? { instructions: child.instructions } : {}),
42
- ...(child.permission ? { permission: child.permission } : {}),
43
- });
44
- }
45
- visit(child);
46
- }
47
- };
48
- visit(root);
49
- return out;
50
- }
51
- function collectSkills(root, opts) {
52
- const scope = opts?.scope ?? 'tree';
53
- const seen = new Set();
54
- const out = [];
55
- const addNode = (node) => {
56
- for (const slug of projectSkillSlugs(node.skills)) {
57
- if (!seen.has(slug)) {
58
- seen.add(slug);
59
- out.push(slug);
60
- }
61
- }
62
- };
63
- addNode(root);
64
- if (scope === 'tree') {
65
- const visit = (node) => {
66
- for (const child of node.children) {
67
- addNode(child);
68
- visit(child);
69
- }
70
- };
71
- visit(root);
72
- }
73
- return out;
74
- }
75
- function collectTools(root, opts) {
76
- const scope = opts?.scope ?? 'root';
77
- const ctx = root.kernel.slug;
78
- if (scope === 'root') {
79
- return projectToolSelection(root.tools, ctx);
80
- }
81
- const out = [...projectToolSelection(root.tools, ctx)];
82
- const visit = (node) => {
83
- for (const child of node.children) {
84
- out.push(...projectToolSelection(child.tools, child.kernel.slug));
85
- visit(child);
86
- }
87
- };
88
- visit(root);
89
- return out;
90
- }
91
- function collectInstructionsBySlug(root) {
92
- return collectDescendantOverlay(root, (child) => normalizeInstructions(child.instructions));
93
- }
94
- function collectPermissionsBySlug(root) {
95
- return collectDescendantOverlay(root, (child) => normalizePermission(child.permission));
96
- }
97
- function collectModelOverridesBySlug(root) {
98
- return collectDescendantOverlay(root, (child) => projectModelOverride(child.modelOverride, child.kernel.slug));
99
- }
100
- function collectDescendantOverlay(root, project) {
101
- const out = {};
102
- const seen = new Set();
103
- const visit = (node) => {
104
- for (const child of node.children) {
105
- const slug = child.kernel.slug;
106
- if (slug.length === 0) {
107
- continue;
108
- }
109
- if (!seen.has(slug)) {
110
- seen.add(slug);
111
- const value = project(child);
112
- if (value !== null) {
113
- out[slug] = value;
114
- }
115
- }
116
- visit(child);
117
- }
118
- };
119
- visit(root);
120
- return out;
121
- }
122
- function appendInstructions(baseSystemPrompt, nodeInstructions) {
123
- const trimmed = nodeInstructions === null ? '' : nodeInstructions.trim();
124
- if (trimmed.length === 0) {
125
- return baseSystemPrompt;
126
- }
127
- if (baseSystemPrompt.length === 0) {
128
- return trimmed;
129
- }
130
- return `${baseSystemPrompt}\n\n${trimmed}`;
131
- }
132
- function normalizeInstructions(raw) {
133
- if (typeof raw !== 'string') {
134
- return null;
135
- }
136
- const trimmed = raw.trim();
137
- return trimmed.length > 0 ? trimmed : null;
138
- }
139
- function normalizePermission(raw) {
140
- if (!raw || typeof raw !== 'object' || Object.keys(raw).length === 0) {
141
- return null;
142
- }
143
- return raw;
144
- }
145
- function projectModelOverride(raw, context) {
146
- if (raw === undefined) {
147
- return null;
148
- }
149
- if (raw.kind === workflow_1.ModelRefKind.CONCRETE) {
150
- if (typeof raw.modelId !== 'string' || raw.modelId.trim().length === 0) {
151
- throw new AgentResolutionError(context, 'concrete modelOverride is missing a modelId');
152
- }
153
- return raw;
154
- }
155
- const modelClass = raw.modelClass;
156
- if (modelClass === undefined ||
157
- !workflow_1.MODEL_CLASS_VALUES.includes(modelClass)) {
158
- throw new AgentResolutionError(context, `strategy modelOverride.modelClass must be one of ${workflow_1.MODEL_CLASS_VALUES.join(', ')}`);
159
- }
160
- return raw;
161
- }
162
- function projectSkillSlugs(skills) {
163
- if (!Array.isArray(skills)) {
164
- return [];
165
- }
166
- return skills
167
- .map((s) => s.slug)
168
- .filter((slug) => typeof slug === 'string' && slug.length > 0);
169
- }
170
- function projectToolSelection(tools, context) {
171
- if (!Array.isArray(tools)) {
172
- return [];
173
- }
174
- const validKinds = new Set(Object.values(mcp_tool_1.ToolProviderKind));
175
- const out = [];
176
- for (const [idx, tool] of tools.entries()) {
177
- if (typeof tool.providerKind !== 'string' ||
178
- !validKinds.has(tool.providerKind)) {
179
- throw new AgentResolutionError(context, `tools[${idx}].providerKind must be one of ${Object.values(mcp_tool_1.ToolProviderKind).join(', ')}`);
180
- }
181
- if (typeof tool.resourceId !== 'string' ||
182
- tool.resourceId.trim().length === 0) {
183
- throw new AgentResolutionError(context, `tools[${idx}].resourceId must be a non-empty string`);
184
- }
185
- if (tool.kind === 'provider') {
186
- out.push({
187
- kind: 'provider',
188
- providerKind: tool.providerKind,
189
- resourceId: tool.resourceId,
190
- });
191
- }
192
- else if (tool.kind === 'tool') {
193
- if (typeof tool.toolName !== 'string' ||
194
- tool.toolName.trim().length === 0) {
195
- throw new AgentResolutionError(context, `tools[${idx}].toolName must be a non-empty string for kind='tool'`);
196
- }
197
- out.push({
198
- kind: 'tool',
199
- providerKind: tool.providerKind,
200
- resourceId: tool.resourceId,
201
- toolName: tool.toolName,
202
- });
203
- }
204
- else {
205
- throw new AgentResolutionError(context, `tools[${idx}].kind must be "provider" or "tool"`);
206
- }
207
- }
208
- return out;
209
- }
210
- function projectAgentToRuntimeConfig(resolved, overlay) {
211
- const root = resolved.root;
212
- const agentRef = `${resolved.slug}@${resolved.version}`;
213
- const rootInstructions = normalizeInstructions(root.instructions);
214
- const overlayInstructions = normalizeInstructions(overlay?.instructions);
215
- const primaryInstructions = appendInstructions(rootInstructions ?? '', overlayInstructions);
216
- const rootModelOverride = projectModelOverride(root.modelOverride, agentRef);
217
- const overlayModelOverride = projectModelOverride(overlay?.modelOverride, `${agentRef}#overlay`);
218
- const rootPermission = normalizePermission(root.permission);
219
- const overlayPermission = normalizePermission(overlay?.permission);
220
- const flattened = flattenAgentTree(root);
221
- return {
222
- agentRef,
223
- primaryAgentSlug: root.kernel.slug,
224
- primaryInstructions: primaryInstructions.length > 0 ? primaryInstructions : null,
225
- primaryPermission: overlayPermission ?? rootPermission,
226
- primaryModelOverride: overlayModelOverride ?? rootModelOverride,
227
- subAgentBindings: flattened.map((n) => ({ ...n })),
228
- subAgentInstructionsBySlug: collectInstructionsBySlug(root),
229
- subAgentPermissionBySlug: collectPermissionsBySlug(root),
230
- subAgentModelOverridesBySlug: collectModelOverridesBySlug(root),
231
- defaultSkillSlugs: collectSkills(root, { scope: 'root' }),
232
- allSkillSlugs: collectSkills(root, { scope: 'tree' }),
233
- defaultToolSelection: collectTools(root, { scope: 'root' }),
234
- };
235
- }
236
- //# sourceMappingURL=composition-resolution.js.map