@springbrand/agent-runtime 0.2.0-alpha.64 → 0.2.0-alpha.66

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@springbrand/agent-runtime",
3
- "version": "0.2.0-alpha.64",
3
+ "version": "0.2.0-alpha.66",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "src",
package/src/index.ts CHANGED
@@ -68,6 +68,7 @@ export type {
68
68
  ResolvedResources,
69
69
  RuntimeAgentContext,
70
70
  RuntimeSettings,
71
+ RuntimeSkillBodyTransform,
71
72
  RuntimeToolBindings,
72
73
  ToolAssemblyResult,
73
74
  } from "./runtime-definition";
@@ -7,6 +7,8 @@ export interface RequestedCapability {
7
7
  readonly kind: "skill" | "tool" | "plan";
8
8
  readonly name: string;
9
9
  readonly label: string;
10
+ /** Stable Resource identity used only to group capabilities in presentation. */
11
+ readonly resourceId?: string;
10
12
  }
11
13
 
12
14
  export interface UIChatRequestBody {
@@ -13,6 +13,7 @@ import type {
13
13
  RuntimeSkillScriptPolicy,
14
14
  WorkspacePort,
15
15
  } from "../../kernel/bindings";
16
+ import type { RuntimeSkillBodyTransform } from "../../runtime-definition";
16
17
  import { STORAGE_LEAF_MAX_CHARS } from "../../layers/context/budget/gate";
17
18
  import { serializeOutput } from "../../lib/artifacts";
18
19
  import { aiToolToPi } from "./ai-adapter";
@@ -33,6 +34,7 @@ export interface SkillPiToolOptions {
33
34
  readonly loader?: WorkerLoader;
34
35
  readonly workspace?: WorkspacePort;
35
36
  readonly tools?: readonly PiToolCandidate[];
37
+ readonly transformSkillBody?: RuntimeSkillBodyTransform;
36
38
  }
37
39
 
38
40
  /**
@@ -116,7 +118,11 @@ function budgetSkillResources(skill: LoadedSkill): LoadedSkill {
116
118
  return { ...skill, resources: kept, body: `${skill.body}\n\n${lines.join("\n")}` };
117
119
  }
118
120
 
119
- function catalogSkillSource(binding: PiSkillBinding): SkillSource {
121
+ function catalogSkillSource(
122
+ binding: PiSkillBinding,
123
+ transformSkillBody: RuntimeSkillBodyTransform | undefined,
124
+ availableToolNames: readonly string[],
125
+ ): SkillSource {
120
126
  const source = binding.source;
121
127
  return {
122
128
  id: source.id,
@@ -132,7 +138,17 @@ function catalogSkillSource(binding: PiSkillBinding): SkillSource {
132
138
  load: async (name) => {
133
139
  const skill = await source.load(name);
134
140
  if (!skill) return null;
135
- const loaded = budgetSkillResources(skill);
141
+ const prepared = transformSkillBody
142
+ ? {
143
+ ...skill,
144
+ body: transformSkillBody({
145
+ name: skill.name,
146
+ body: skill.body,
147
+ availableToolNames,
148
+ }),
149
+ }
150
+ : skill;
151
+ const loaded = budgetSkillResources(prepared);
136
152
  const hasOversizedResource = skill.resources?.some((resource) =>
137
153
  typeof resource.size === "number" &&
138
154
  resource.size > SKILL_RESOURCE_BUDGET_BYTES
@@ -420,8 +436,14 @@ export async function skillPiToolCandidates(
420
436
  ): Promise<PiToolCandidate[]> {
421
437
  if (bindings.length === 0) return [];
422
438
 
439
+ const availableToolNames = (options.tools ?? []).map(({ tool }) => tool.name);
440
+
423
441
  const registry = new SkillRegistry(
424
- bindings.map(catalogSkillSource),
442
+ bindings.map((binding) => catalogSkillSource(
443
+ binding,
444
+ options.transformSkillBody,
445
+ availableToolNames,
446
+ )),
425
447
  scriptRunner(bindings, options),
426
448
  );
427
449
  await registry.load();
@@ -44,6 +44,7 @@ import type {
44
44
  RuntimeSettings,
45
45
  RuntimeExtensionContribution,
46
46
  RuntimeProfileContribution,
47
+ RuntimeSkillBodyTransform,
47
48
  RuntimeSkillContribution,
48
49
  RuntimeToolSurfacePolicy,
49
50
  } from "./runtime-definition";
@@ -90,6 +91,7 @@ export interface RuntimeAssemblyInput {
90
91
  readonly sandbox?: RuntimeSandboxPort;
91
92
  readonly memory?: RuntimeMemoryPort;
92
93
  readonly hostTools: readonly PiToolCandidate[];
94
+ readonly transformSkillBody?: RuntimeSkillBodyTransform;
93
95
  readonly skills: readonly RuntimeSkillContribution[];
94
96
  readonly connectors: readonly RuntimeMcpServer[];
95
97
  readonly gateway?: RuntimeGatewayPort;
@@ -168,6 +170,7 @@ interface ToolSurfaceInput {
168
170
  readonly profile: RuntimeMemoryProfile;
169
171
  };
170
172
  readonly hostTools: readonly PiToolCandidate[];
173
+ readonly transformSkillBody?: RuntimeSkillBodyTransform;
171
174
  readonly skills: readonly RuntimeSkillSourceBinding[];
172
175
  readonly enabledSubagents: readonly string[];
173
176
  readonly webSearch?: Parameters<typeof basePiToolCandidates>[0];
@@ -236,6 +239,9 @@ async function createToolSurface(
236
239
  loader: input.platform.loader,
237
240
  ...(input.workspace ? { workspace: input.workspace } : {}),
238
241
  tools: scriptCandidates,
242
+ ...(input.transformSkillBody
243
+ ? { transformSkillBody: input.transformSkillBody }
244
+ : {}),
239
245
  })),
240
246
  ...baseCandidates,
241
247
  ...memoryCandidates,
@@ -369,6 +375,7 @@ class RuntimeBuilder {
369
375
  private memoryProfile: RuntimeMemoryProfile = DISABLED_MEMORY;
370
376
  private memory?: RuntimeMemoryPort;
371
377
  private readonly hostTools: PiToolCandidate[] = [];
378
+ private transformSkillBody?: RuntimeSkillBodyTransform;
372
379
  private toolPolicy?: RuntimeToolSurfacePolicy;
373
380
  private readonly skillSources = new Map<
374
381
  string,
@@ -404,6 +411,7 @@ class RuntimeBuilder {
404
411
  this.memoryProfile = input.memoryProfile;
405
412
  this.memory = input.memory;
406
413
  this.hostTools.push(...input.hostTools);
414
+ this.transformSkillBody = input.transformSkillBody;
407
415
  this.toolPolicy = input.toolPolicy;
408
416
  for (const skill of input.skills) this.addSkill(skill);
409
417
  for (const connector of input.connectors) this.addConnector(connector);
@@ -619,6 +627,9 @@ class RuntimeBuilder {
619
627
  [...this.enabledSubagents],
620
628
  ),
621
629
  ],
630
+ ...(this.transformSkillBody
631
+ ? { transformSkillBody: this.transformSkillBody }
632
+ : {}),
622
633
  skills: skillSources,
623
634
  enabledSubagents: [...this.enabledSubagents],
624
635
  ...(webSearch ? { webSearch } : {}),
@@ -786,6 +797,9 @@ export async function assembleRuntimeSnapshot<
786
797
  ? { subagents: toolAssembly.bindings.subagents }
787
798
  : {}),
788
799
  hostTools,
800
+ ...(resources.transformSkillBody
801
+ ? { transformSkillBody: resources.transformSkillBody }
802
+ : {}),
789
803
  skills:
790
804
  input.ctx.role === "primary" && toolAssembly.bindings?.workspace
791
805
  ? [...BUILT_IN_RUNTIME_SKILLS, ...resources.skills]
@@ -82,12 +82,19 @@ export interface ResolvedConnectors {
82
82
  readonly degradations: readonly RuntimeDegradation[];
83
83
  }
84
84
 
85
+ export type RuntimeSkillBodyTransform = (input: {
86
+ readonly name: string;
87
+ readonly body: string;
88
+ readonly availableToolNames: readonly string[];
89
+ }) => string;
90
+
85
91
  export interface ResolvedResources {
86
92
  readonly settings: RuntimeSettings;
87
93
  readonly provider: RuntimeProviderPort;
88
94
  readonly platform: RuntimePlatformPort;
89
95
  readonly turnEvents?: RuntimeTurnEventsPort;
90
96
  readonly admission?: RuntimeSubmissionAdmissionHook;
97
+ readonly transformSkillBody?: RuntimeSkillBodyTransform;
91
98
  readonly skills: readonly RuntimeSkillContribution[];
92
99
  readonly extensions: readonly RuntimeExtensionContribution[];
93
100
  readonly connectors: ResolvedConnectors;