@openagentpack/sdk 0.7.2 → 0.8.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.
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  UserError,
3
3
  inspectProjectSource
4
- } from "./chunk-HLZOSZ7B.js";
4
+ } from "./chunk-ZOMPZ7R6.js";
5
5
 
6
6
  // src/internal/project-versions/directory.ts
7
7
  import { createHash, randomUUID } from "crypto";
@@ -14,7 +14,7 @@ import {
14
14
  resolveFetch,
15
15
  resolveTargetProviders,
16
16
  skillNameFromFiles
17
- } from "./chunk-HLZOSZ7B.js";
17
+ } from "./chunk-ZOMPZ7R6.js";
18
18
 
19
19
  // src/internal/core/project-runtime.ts
20
20
  function createProjectRuntime(input) {
@@ -138,6 +138,185 @@ function parseSkillManifestName(content) {
138
138
  // src/internal/executor/executor.ts
139
139
  import { basename as basename2, dirname as dirname3, resolve as resolve4 } from "path";
140
140
 
141
+ // src/internal/executor/resolver.ts
142
+ function resolveRef(state, address) {
143
+ return state.getResource(address)?.remote_id;
144
+ }
145
+ function requireRef(state, address) {
146
+ const id = resolveRef(state, address);
147
+ if (!id) {
148
+ throw new UserError(
149
+ `Resource ${address.provider}.${address.type}.${address.name} not found in state. Run \`agents apply\` first.`
150
+ );
151
+ }
152
+ return id;
153
+ }
154
+ function resolveSkillRefs(agent, provider, state) {
155
+ const skillIds = [];
156
+ for (const skill of agent.skills ?? []) {
157
+ if (typeof skill === "string") {
158
+ const id = requireRef(state, { type: "skill", name: skill, provider });
159
+ skillIds.push({ type: "custom", skill_id: id });
160
+ } else {
161
+ const resolvedId = skill.type === "custom" ? resolveRef(state, {
162
+ type: "skill",
163
+ name: skill.skill_id,
164
+ provider
165
+ }) ?? skill.skill_id : skill.skill_id;
166
+ skillIds.push({
167
+ type: skill.type,
168
+ skill_id: resolvedId,
169
+ version: skill.version
170
+ });
171
+ }
172
+ }
173
+ return skillIds;
174
+ }
175
+ function resolveMultiagentRoster(agent, provider, state, resourceType) {
176
+ return {
177
+ type: "coordinator",
178
+ members: (agent.multiagent?.agents ?? []).map((member) => {
179
+ if (typeof member !== "string") {
180
+ if (resourceType === "template") {
181
+ throw new UserError(
182
+ `qoder.template.multiagent.external_member: Forward coordinator cannot reference external Managed Agent '${member.agent_id}'.`
183
+ );
184
+ }
185
+ return { resource_type: "agent", remote_id: member.agent_id };
186
+ }
187
+ return {
188
+ logical_name: member,
189
+ resource_type: resourceType,
190
+ remote_id: requireRef(state, { type: resourceType, name: member, provider })
191
+ };
192
+ })
193
+ };
194
+ }
195
+ function resolveAgentRefs(agentName, config, provider, state) {
196
+ const agent = config.agents?.[agentName];
197
+ if (!agent) throw new UserError(`Agent '${agentName}' not found in config`);
198
+ const refs = {
199
+ skill_ids: resolveSkillRefs(agent, provider, state)
200
+ };
201
+ if (agent.multiagent && resolveAgentMaterialization(provider, agent).resourceType === "agent") {
202
+ refs.multiagent = resolveMultiagentRoster(agent, provider, state, "agent");
203
+ }
204
+ return refs;
205
+ }
206
+ function resolveTemplateRefs(agentName, config, provider, state) {
207
+ const agent = config.agents?.[agentName];
208
+ if (!agent) throw new UserError(`Agent '${agentName}' not found in config`);
209
+ if (!agent.environment) {
210
+ throw new UserError(`Forward template '${agentName}' must declare an environment.`);
211
+ }
212
+ const environment = config.environments?.[agent.environment];
213
+ if (!environment) throw new UserError(`Environment '${agent.environment}' is not defined in config.`);
214
+ const agentRefs = resolveAgentRefs(agentName, config, provider, state);
215
+ const memoryStoreIds = (agent.memory_stores ?? []).map(
216
+ (memoryStore) => requireRef(state, { type: "memory_store", name: memoryStore, provider })
217
+ );
218
+ const identityName = config.defaults?.identity;
219
+ return {
220
+ ...agentRefs,
221
+ ...agent.multiagent ? { multiagent: resolveMultiagentRoster(agent, provider, state, "template") } : {},
222
+ environment_id: environment.environment_id ?? requireRef(state, { type: "environment", name: agent.environment, provider }),
223
+ ...agent.tunnel ? { tunnel_id: resolveTunnelIdFromConfig(config, agent.tunnel, provider) } : {},
224
+ vault_ids: agent.vault ? [requireRef(state, { type: "vault", name: agent.vault, provider })] : [],
225
+ file_ids: (agent.files ?? []).filter((file) => typeof file === "string").map((file) => requireRef(state, { type: "file", name: file, provider })),
226
+ memory_store_ids: memoryStoreIds,
227
+ owned_memory_store_ids: state.listResources().filter(
228
+ (resource) => resource.address.provider === provider && resource.address.type === "memory_store" && resource.api_mode === "forward" && typeof resource.remote_id === "string"
229
+ ).map((resource) => resource.remote_id),
230
+ ...identityName ? { identity_id: requireRef(state, { type: "identity", name: identityName, provider }) } : {}
231
+ };
232
+ }
233
+ function resolveDeploymentRefs(deploymentName, config, provider, state) {
234
+ const dep = config.deployments?.[deploymentName];
235
+ if (!dep) throw new UserError(`Deployment '${deploymentName}' not found in config`);
236
+ const agent = config.agents?.[dep.agent];
237
+ if (!agent) {
238
+ throw new UserError(`Deployment '${deploymentName}' references unknown agent '${dep.agent}'`);
239
+ }
240
+ const agent_id = requireRef(state, {
241
+ type: "agent",
242
+ name: dep.agent,
243
+ provider
244
+ });
245
+ const envName = dep.environment ?? agent.environment;
246
+ if (!envName) {
247
+ throw new UserError(
248
+ `Deployment '${deploymentName}' has no environment and agent '${dep.agent}' does not declare one`
249
+ );
250
+ }
251
+ const envDecl = config.environments?.[envName];
252
+ if (!envDecl) {
253
+ throw new UserError(`Environment '${envName}' is not defined in config.`);
254
+ }
255
+ const environment_id = envDecl.environment_id ?? requireRef(state, {
256
+ type: "environment",
257
+ name: envName,
258
+ provider
259
+ });
260
+ const tunnelName = dep.tunnel ?? agent.tunnel;
261
+ const tunnel_id = tunnelName ? resolveTunnelIdFromConfig(config, tunnelName, provider) : void 0;
262
+ const vaultNames = dep.vaults ?? (agent.vault ? [agent.vault] : []);
263
+ const vault_ids = vaultNames.map((v) => requireRef(state, { type: "vault", name: v, provider }));
264
+ const msNames = /* @__PURE__ */ new Set();
265
+ for (const m of dep.memory_stores ?? []) msNames.add(m);
266
+ for (const r of dep.resources ?? []) {
267
+ if (r.type === "memory_store") msNames.add(r.memory_store);
268
+ }
269
+ if (msNames.size === 0) {
270
+ for (const m of agent.memory_stores ?? []) msNames.add(m);
271
+ }
272
+ const memory_store_ids = {};
273
+ for (const m of msNames) {
274
+ memory_store_ids[m] = requireRef(state, {
275
+ type: "memory_store",
276
+ name: m,
277
+ provider
278
+ });
279
+ }
280
+ return {
281
+ agent_id,
282
+ agent_version: dep.agent_version,
283
+ environment_id,
284
+ tunnel_id,
285
+ vault_ids,
286
+ memory_store_ids
287
+ };
288
+ }
289
+ function resolveChannelRefs(channelName, config, provider, state) {
290
+ const channel = config.channels?.[channelName];
291
+ if (!channel) throw new UserError(`Channel '${channelName}' not found in config`);
292
+ if (channel.mode === "pairing") {
293
+ return {};
294
+ }
295
+ if (!channel.agent) {
296
+ throw new UserError(`Channel '${channelName}' is fixed mode and must declare agent`);
297
+ }
298
+ const agent = config.agents?.[channel.agent];
299
+ if (!agent) throw new UserError(`Channel '${channelName}' references unknown agent '${channel.agent}'`);
300
+ const agentType = agent.delivery?.[provider]?.type === "forward" ? "template" : "agent";
301
+ const agent_id = requireRef(state, { type: agentType, name: channel.agent, provider });
302
+ const identityName = channel.identity ?? config.defaults?.identity;
303
+ if (!identityName) {
304
+ throw new UserError(`Channel '${channelName}' must declare identity or use defaults.identity.`);
305
+ }
306
+ const identity_id = requireRef(state, { type: "identity", name: identityName, provider });
307
+ return { identity_id, agent_id };
308
+ }
309
+ function resolveTunnelIdFromConfig(config, tunnelName, provider) {
310
+ if (provider !== "qoder") {
311
+ throw new UserError("Tunnels are supported only by Qoder BYOC sessions.");
312
+ }
313
+ const tunnel = config.tunnels?.[tunnelName];
314
+ if (!tunnel) {
315
+ throw new UserError(`Tunnel '${tunnelName}' is not defined in config. Declare it under the 'tunnels:' section.`);
316
+ }
317
+ return tunnel.tunnel_id;
318
+ }
319
+
141
320
  // src/internal/utils/hash.ts
142
321
  import { createHash } from "crypto";
143
322
  function sha256(data) {
@@ -189,10 +368,17 @@ function getResourceDeclaration(address, config) {
189
368
  }
190
369
 
191
370
  // src/internal/planner/comparable.ts
192
- function computeComparableDesiredHash(address, config, provider) {
371
+ function resolveComparableRefs(address, config, state) {
372
+ if (!state || !config) return void 0;
373
+ if (address.type === "agent") return resolveAgentRefs(address.name, config, address.provider, state);
374
+ if (address.type === "template") return resolveTemplateRefs(address.name, config, address.provider, state);
375
+ return void 0;
376
+ }
377
+ function computeComparableDesiredHash(address, config, provider, state) {
193
378
  const decl = getResourceDeclaration(address, config);
194
379
  if (!decl || !provider.normalizeDesiredResource) return void 0;
195
- const comparable = provider.normalizeDesiredResource(address.type, address.name, decl);
380
+ const refs = resolveComparableRefs(address, config, state);
381
+ const comparable = provider.normalizeDesiredResource(address.type, address.name, decl, refs);
196
382
  return comparable === null ? void 0 : contentHash(comparable);
197
383
  }
198
384
 
@@ -423,166 +609,6 @@ function addressKey(addr) {
423
609
  return `${addr.provider}.${addr.type}.${addr.name}`;
424
610
  }
425
611
 
426
- // src/internal/executor/resolver.ts
427
- function resolveRef(state, address) {
428
- return state.getResource(address)?.remote_id;
429
- }
430
- function requireRef(state, address) {
431
- const id = resolveRef(state, address);
432
- if (!id) {
433
- throw new UserError(
434
- `Resource ${address.provider}.${address.type}.${address.name} not found in state. Run \`agents apply\` first.`
435
- );
436
- }
437
- return id;
438
- }
439
- function resolveAgentRefs(agentName, config, provider, state) {
440
- const agent = config.agents?.[agentName];
441
- if (!agent) throw new UserError(`Agent '${agentName}' not found in config`);
442
- const refs = {
443
- skill_ids: []
444
- };
445
- if (agent.skills) {
446
- for (const skill of agent.skills) {
447
- if (typeof skill === "string") {
448
- const id = requireRef(state, { type: "skill", name: skill, provider });
449
- refs.skill_ids.push({ type: "custom", skill_id: id });
450
- } else {
451
- const resolvedId = skill.type === "custom" ? resolveRef(state, {
452
- type: "skill",
453
- name: skill.skill_id,
454
- provider
455
- }) ?? skill.skill_id : skill.skill_id;
456
- refs.skill_ids.push({
457
- type: skill.type,
458
- skill_id: resolvedId,
459
- version: skill.version
460
- });
461
- }
462
- }
463
- }
464
- if (agent.multiagent) {
465
- refs.multiagent_agent_ids = [];
466
- for (const subName of agent.multiagent.agents) {
467
- const id = resolveRef(state, { type: "agent", name: subName, provider });
468
- if (id) refs.multiagent_agent_ids.push(id);
469
- }
470
- }
471
- return refs;
472
- }
473
- function resolveTemplateRefs(agentName, config, provider, state) {
474
- const agent = config.agents?.[agentName];
475
- if (!agent) throw new UserError(`Agent '${agentName}' not found in config`);
476
- if (!agent.environment) {
477
- throw new UserError(`Forward template '${agentName}' must declare an environment.`);
478
- }
479
- const environment = config.environments?.[agent.environment];
480
- if (!environment) throw new UserError(`Environment '${agent.environment}' is not defined in config.`);
481
- const agentRefs = resolveAgentRefs(agentName, config, provider, state);
482
- const memoryStoreIds = (agent.memory_stores ?? []).map(
483
- (memoryStore) => requireRef(state, { type: "memory_store", name: memoryStore, provider })
484
- );
485
- const identityName = config.defaults?.identity;
486
- return {
487
- ...agentRefs,
488
- environment_id: environment.environment_id ?? requireRef(state, { type: "environment", name: agent.environment, provider }),
489
- ...agent.tunnel ? { tunnel_id: resolveTunnelIdFromConfig(config, agent.tunnel, provider) } : {},
490
- vault_ids: agent.vault ? [requireRef(state, { type: "vault", name: agent.vault, provider })] : [],
491
- file_ids: (agent.files ?? []).filter((file) => typeof file === "string").map((file) => requireRef(state, { type: "file", name: file, provider })),
492
- memory_store_ids: memoryStoreIds,
493
- owned_memory_store_ids: state.listResources().filter(
494
- (resource) => resource.address.provider === provider && resource.address.type === "memory_store" && resource.api_mode === "forward" && typeof resource.remote_id === "string"
495
- ).map((resource) => resource.remote_id),
496
- ...identityName ? { identity_id: requireRef(state, { type: "identity", name: identityName, provider }) } : {}
497
- };
498
- }
499
- function resolveDeploymentRefs(deploymentName, config, provider, state) {
500
- const dep = config.deployments?.[deploymentName];
501
- if (!dep) throw new UserError(`Deployment '${deploymentName}' not found in config`);
502
- const agent = config.agents?.[dep.agent];
503
- if (!agent) {
504
- throw new UserError(`Deployment '${deploymentName}' references unknown agent '${dep.agent}'`);
505
- }
506
- const agent_id = requireRef(state, {
507
- type: "agent",
508
- name: dep.agent,
509
- provider
510
- });
511
- const envName = dep.environment ?? agent.environment;
512
- if (!envName) {
513
- throw new UserError(
514
- `Deployment '${deploymentName}' has no environment and agent '${dep.agent}' does not declare one`
515
- );
516
- }
517
- const envDecl = config.environments?.[envName];
518
- if (!envDecl) {
519
- throw new UserError(`Environment '${envName}' is not defined in config.`);
520
- }
521
- const environment_id = envDecl.environment_id ?? requireRef(state, {
522
- type: "environment",
523
- name: envName,
524
- provider
525
- });
526
- const tunnelName = dep.tunnel ?? agent.tunnel;
527
- const tunnel_id = tunnelName ? resolveTunnelIdFromConfig(config, tunnelName, provider) : void 0;
528
- const vaultNames = dep.vaults ?? (agent.vault ? [agent.vault] : []);
529
- const vault_ids = vaultNames.map((v) => requireRef(state, { type: "vault", name: v, provider }));
530
- const msNames = /* @__PURE__ */ new Set();
531
- for (const m of dep.memory_stores ?? []) msNames.add(m);
532
- for (const r of dep.resources ?? []) {
533
- if (r.type === "memory_store") msNames.add(r.memory_store);
534
- }
535
- if (msNames.size === 0) {
536
- for (const m of agent.memory_stores ?? []) msNames.add(m);
537
- }
538
- const memory_store_ids = {};
539
- for (const m of msNames) {
540
- memory_store_ids[m] = requireRef(state, {
541
- type: "memory_store",
542
- name: m,
543
- provider
544
- });
545
- }
546
- return {
547
- agent_id,
548
- agent_version: dep.agent_version,
549
- environment_id,
550
- tunnel_id,
551
- vault_ids,
552
- memory_store_ids
553
- };
554
- }
555
- function resolveChannelRefs(channelName, config, provider, state) {
556
- const channel = config.channels?.[channelName];
557
- if (!channel) throw new UserError(`Channel '${channelName}' not found in config`);
558
- if (channel.mode === "pairing") {
559
- return {};
560
- }
561
- if (!channel.agent) {
562
- throw new UserError(`Channel '${channelName}' is fixed mode and must declare agent`);
563
- }
564
- const agent = config.agents?.[channel.agent];
565
- if (!agent) throw new UserError(`Channel '${channelName}' references unknown agent '${channel.agent}'`);
566
- const agentType = agent.delivery?.[provider]?.type === "forward" ? "template" : "agent";
567
- const agent_id = requireRef(state, { type: agentType, name: channel.agent, provider });
568
- const identityName = channel.identity ?? config.defaults?.identity;
569
- if (!identityName) {
570
- throw new UserError(`Channel '${channelName}' must declare identity or use defaults.identity.`);
571
- }
572
- const identity_id = requireRef(state, { type: "identity", name: identityName, provider });
573
- return { identity_id, agent_id };
574
- }
575
- function resolveTunnelIdFromConfig(config, tunnelName, provider) {
576
- if (provider !== "qoder") {
577
- throw new UserError("Tunnels are supported only by Qoder BYOC sessions.");
578
- }
579
- const tunnel = config.tunnels?.[tunnelName];
580
- if (!tunnel) {
581
- throw new UserError(`Tunnel '${tunnelName}' is not defined in config. Declare it under the 'tunnels:' section.`);
582
- }
583
- return tunnel.tunnel_id;
584
- }
585
-
586
612
  // src/internal/executor/skill-resolver.ts
587
613
  import { dirname as dirname2 } from "path";
588
614
  async function resolveSkillFiles(decl, ctx) {
@@ -1229,7 +1255,7 @@ async function executeActionInner(action, provider, ctx) {
1229
1255
  throw new UserError(`Unknown resource type: ${type}`);
1230
1256
  }
1231
1257
  const hash = await computeResourceHash(address, ctx.config, ctx.configPath, ctx.state);
1232
- const comparableHash = computeComparableDesiredHash(address, ctx.config, provider);
1258
+ const comparableHash = computeComparableDesiredHash(address, ctx.config, provider, ctx.state);
1233
1259
  let remoteHash = comparableHash;
1234
1260
  let remoteSnapshot;
1235
1261
  const remote = await readComparableIfSupported(
@@ -1464,6 +1490,7 @@ function buildDependencyGraph(config, targetProviders) {
1464
1490
  }
1465
1491
  if (decl.multiagent && isSupported(caps, "multiagent")) {
1466
1492
  for (const subName of decl.multiagent.agents) {
1493
+ if (typeof subName !== "string") continue;
1467
1494
  const subDecl = config.agents[subName];
1468
1495
  const subType = subDecl ? resolveAgentMaterialization(provider, subDecl).resourceType : "agent";
1469
1496
  const subAddr = { type: subType, name: subName, provider };
@@ -1873,7 +1900,12 @@ async function refreshState(state, providers, options = {}) {
1873
1900
  continue;
1874
1901
  }
1875
1902
  const remoteHash = contentHash(remote2.comparable);
1876
- const desiredComparable = decl ? provider.normalizeDesiredResource(res.address.type, res.address.name, decl) : null;
1903
+ const desiredComparable = decl ? provider.normalizeDesiredResource(
1904
+ res.address.type,
1905
+ res.address.name,
1906
+ decl,
1907
+ resolveComparableRefs(res.address, options.config, state)
1908
+ ) : null;
1877
1909
  const desiredComparableHash = desiredComparable === null ? void 0 : contentHash(desiredComparable);
1878
1910
  const baselineHash = res.desired_comparable_hash ?? desiredComparableHash ?? remoteHash;
1879
1911
  const driftStatus = baselineHash && remoteHash !== baselineHash ? "drifted" : "in_sync";
@@ -2423,12 +2455,12 @@ export {
2423
2455
  readProjectRuntime,
2424
2456
  writeProjectRuntime,
2425
2457
  getRuntimeProvider,
2458
+ requireRef,
2459
+ resolveDeploymentRefs,
2426
2460
  contentHash,
2427
2461
  computeResourceHash,
2428
2462
  emitRuntimeFeedback,
2429
2463
  addressKey,
2430
- requireRef,
2431
- resolveDeploymentRefs,
2432
2464
  inspectSkillSource,
2433
2465
  collectDependencyClosure,
2434
2466
  buildDependencyGraph,