operon-agents-core 0.1.0-alpha.2 → 0.1.0-alpha.4

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 (63) hide show
  1. package/dist/agent/index.d.ts +2 -2
  2. package/dist/agent/index.js +1 -1
  3. package/dist/agent/runner.d.ts +21 -15
  4. package/dist/agent/runner.js +23 -26
  5. package/dist/agent/session.d.ts +67 -73
  6. package/dist/agent/session.js +170 -174
  7. package/dist/agent/workflow/tool.js +8 -21
  8. package/dist/capabilities/assembler.d.ts +6 -4
  9. package/dist/capabilities/assembler.js +10 -5
  10. package/dist/capabilities/background/index.js +33 -26
  11. package/dist/capabilities/capability-state.d.ts +5 -7
  12. package/dist/capabilities/capability-state.js +6 -4
  13. package/dist/capabilities/capability.d.ts +52 -40
  14. package/dist/capabilities/compaction/index.js +5 -4
  15. package/dist/capabilities/goal/index.d.ts +1 -0
  16. package/dist/capabilities/goal/index.js +13 -6
  17. package/dist/capabilities/index.d.ts +3 -3
  18. package/dist/capabilities/index.js +2 -2
  19. package/dist/capabilities/plan/index.js +12 -6
  20. package/dist/capabilities/skills/flow-provider.js +3 -3
  21. package/dist/capabilities/skills/index.d.ts +12 -0
  22. package/dist/capabilities/skills/index.js +38 -24
  23. package/dist/capabilities/skills/registry.d.ts +3 -4
  24. package/dist/capabilities/skills/registry.js +4 -7
  25. package/dist/capabilities/skills/service.js +1 -1
  26. package/dist/capabilities/skills/skill-tool.d.ts +2 -0
  27. package/dist/capabilities/skills/skill-tool.js +1 -1
  28. package/dist/capabilities/task/index.js +11 -5
  29. package/dist/capabilities/todo/index.js +12 -6
  30. package/dist/capabilities/tool-provider.d.ts +3 -3
  31. package/dist/capabilities/user-hooks/index.js +22 -16
  32. package/dist/capabilities/workflow/index.d.ts +4 -2
  33. package/dist/capabilities/workflow/index.js +14 -7
  34. package/dist/commands/index.js +6 -4
  35. package/dist/events/events.d.ts +2 -1
  36. package/dist/events/publisher.js +1 -1
  37. package/dist/index.d.ts +2 -1
  38. package/dist/index.js +2 -1
  39. package/dist/internal.d.ts +2 -0
  40. package/dist/internal.js +2 -0
  41. package/dist/loop/steer.d.ts +2 -0
  42. package/dist/loop/steer.js +7 -2
  43. package/dist/mcp/capability.js +22 -17
  44. package/dist/mcp/filter.d.ts +2 -2
  45. package/dist/mcp/index.d.ts +1 -1
  46. package/dist/mcp/index.js +1 -1
  47. package/dist/mcp/manager.d.ts +45 -2
  48. package/dist/mcp/manager.js +162 -11
  49. package/dist/plugins/index.js +10 -4
  50. package/dist/scope/index.d.ts +7 -0
  51. package/dist/scope/index.js +4 -0
  52. package/dist/scope/scope.d.ts +143 -0
  53. package/dist/scope/scope.js +406 -0
  54. package/dist/scope/token.d.ts +29 -0
  55. package/dist/scope/token.js +29 -0
  56. package/dist/scope/tokens.d.ts +98 -0
  57. package/dist/scope/tokens.js +63 -0
  58. package/dist/store/index.d.ts +1 -1
  59. package/dist/store/origin.d.ts +9 -0
  60. package/dist/store/store.d.ts +6 -2
  61. package/dist/testing.d.ts +62 -0
  62. package/dist/testing.js +118 -0
  63. package/package.json +1 -1
@@ -1,5 +1,9 @@
1
1
  import type { ImageContent, Message, TextContent, Usage } from "../protocol/index.ts";
2
- import type { ExternalPromptOrigin, PromptOrigin } from "./origin.ts";
2
+ import type { ExternalPromptOrigin, PromptOrigin, UserPromptOrigin } from "./origin.ts";
3
+ /** Who an accepted input (`inbox.received`) is from — see that record's doc. */
4
+ export type InboxOrigin = (UserPromptOrigin & {
5
+ readonly deliveryId: string;
6
+ }) | ExternalPromptOrigin;
3
7
  /**
4
8
  * A record in a session's append log. The log is a FLAT, linear, append-only stream
5
9
  * — NOT a tree. Each address has its own shard; a shard's
@@ -42,7 +46,7 @@ export type AgentRecordBody = {
42
46
  } | {
43
47
  readonly type: "inbox.received";
44
48
  readonly input: string;
45
- readonly origin: ExternalPromptOrigin;
49
+ readonly origin: InboxOrigin;
46
50
  /** Delivery mode as accepted — `steer` targets a running turn, `follow_up` queues after it. */
47
51
  readonly mode: "auto" | "steer" | "follow_up";
48
52
  } | {
@@ -0,0 +1,62 @@
1
+ /**
2
+ * Scope-wiring helpers for tests and quick scripts (exported via `operon-agents-core/internal`).
3
+ *
4
+ * A test describes a session's objects as a flat options bag; these turn that bag into the
5
+ * harness/session scopes the engine actually takes. Nothing here is a compatibility layer for
6
+ * production code — hosts compose scopes through the harness hooks.
7
+ */
8
+ import { Scope } from "./scope/scope.ts";
9
+ import { Runner, type RunnerConfig } from "./agent/runner.ts";
10
+ import { Session, type SessionOpenOptions } from "./agent/session.ts";
11
+ import type { Machine, MachineFactory } from "./tool/machine.ts";
12
+ import type { SessionStore, AgentRecord } from "./store/index.ts";
13
+ import { type EventSink, type EventPublicationMode } from "./events/index.ts";
14
+ import type { TracingProcessor } from "./tracing/index.ts";
15
+ import type { Responder } from "./permission/types.ts";
16
+ import type { PermissionManagerOptions } from "./permission/manager.ts";
17
+ import type { Capability, ProvisionContext, RunContext } from "./capabilities/capability.ts";
18
+ import { SteerBus } from "./loop/steer.ts";
19
+ import type { BackgroundSpawner } from "./tool/background.ts";
20
+ import type { Logger } from "./logging/index.ts";
21
+ export interface TestSessionWiring {
22
+ readonly machine?: Machine | MachineFactory;
23
+ readonly store?: SessionStore;
24
+ readonly events?: EventSink;
25
+ readonly tracing?: TracingProcessor;
26
+ readonly responder?: Responder;
27
+ readonly permission?: PermissionManagerOptions;
28
+ readonly capabilities?: readonly Capability[];
29
+ readonly steer?: SteerBus;
30
+ readonly background?: BackgroundSpawner;
31
+ readonly eventPublication?: EventPublicationMode;
32
+ readonly logger?: Logger;
33
+ }
34
+ export type TestRunnerOptions<TContext = unknown> = TestSessionWiring & RunnerConfig<TContext>;
35
+ /** A harness scope carrying the harness-tier parts of a wiring bag. */
36
+ export declare function testHarnessScope(wiring?: TestSessionWiring): Scope<"harness">;
37
+ /** Register the session-tier parts of a wiring bag on a session scope (skipping what's set). */
38
+ export declare function wireTestSession(scope: Scope<"session">, wiring: TestSessionWiring): void;
39
+ /** `new Runner(...)` for tests: the wiring bag becomes a harness scope + a per-session hook. */
40
+ export declare function testRunner<TContext = unknown>(options?: TestRunnerOptions<TContext>): Runner<TContext>;
41
+ export interface TestSessionOptions extends TestSessionWiring, SessionOpenOptions {
42
+ readonly sessionId?: string;
43
+ readonly signal?: AbortSignal;
44
+ /** Reuse an existing harness scope (e.g. a runner's) instead of building one from the bag. */
45
+ readonly parent?: Scope<"harness" | "workspace">;
46
+ readonly preloadedLog?: readonly AgentRecord[];
47
+ }
48
+ /** `Session.open(...)` for tests: the wiring bag becomes a session scope under a harness scope. */
49
+ export declare function openTestSession(options?: TestSessionOptions): Promise<Session>;
50
+ export interface TestCapabilityHandle {
51
+ readonly ctx: ProvisionContext;
52
+ /** The last provision's instance (what `cap.service` used to be). */
53
+ readonly service: unknown;
54
+ close(): Promise<void>;
55
+ }
56
+ /** A session scope wired from the bag, with the defaults `Session.open` would provide. */
57
+ export declare function testSessionScope(wiring?: TestSessionWiring): Scope<"session">;
58
+ export declare function testProvisionContext(wiring?: TestSessionWiring): ProvisionContext;
59
+ export declare function testRunContext(wiring?: TestSessionWiring): RunContext;
60
+ /** Run a capability's provisions on a fresh session scope — what `Session.open` does for it. */
61
+ export declare function openCapability(cap: Capability, wiring?: TestSessionWiring): Promise<TestCapabilityHandle>;
62
+ //# sourceMappingURL=testing.d.ts.map
@@ -0,0 +1,118 @@
1
+ /**
2
+ * Scope-wiring helpers for tests and quick scripts (exported via `operon-agents-core/internal`).
3
+ *
4
+ * A test describes a session's objects as a flat options bag; these turn that bag into the
5
+ * harness/session scopes the engine actually takes. Nothing here is a compatibility layer for
6
+ * production code — hosts compose scopes through the harness hooks.
7
+ */
8
+ import { Scope } from "./scope/scope.js";
9
+ import { T } from "./scope/tokens.js";
10
+ import { Runner } from "./agent/runner.js";
11
+ import { Session } from "./agent/session.js";
12
+ import { ListenerSink } from "./events/index.js";
13
+ import { InjectionManager } from "./capabilities/injection.js";
14
+ import { readLog } from "./capabilities/capability-state.js";
15
+ import { SteerBus } from "./loop/steer.js";
16
+ import { NullMachine } from "./tool/machine-null.js";
17
+ /** A harness scope carrying the harness-tier parts of a wiring bag. */
18
+ export function testHarnessScope(wiring = {}) {
19
+ const harness = new Scope("harness");
20
+ if (wiring.machine !== undefined)
21
+ harness.register(T.MachineFactory, wiring.machine, { owned: false });
22
+ if (wiring.tracing !== undefined)
23
+ harness.register(T.Tracing, wiring.tracing, { owned: false });
24
+ if (wiring.logger !== undefined)
25
+ harness.register(T.Logger, wiring.logger, { owned: false });
26
+ if (wiring.eventPublication !== undefined)
27
+ harness.register(T.EventPublication, wiring.eventPublication);
28
+ return harness;
29
+ }
30
+ /** Register the session-tier parts of a wiring bag on a session scope (skipping what's set). */
31
+ export function wireTestSession(scope, wiring) {
32
+ if (wiring.store !== undefined && !scope.hasLocal(T.StoreBackend))
33
+ scope.register(T.StoreBackend, wiring.store, { owned: false });
34
+ if (wiring.events !== undefined && !scope.hasLocal(T.Events))
35
+ scope.register(T.Events, wiring.events, { owned: false });
36
+ if (wiring.responder !== undefined && !scope.hasLocal(T.Responder))
37
+ scope.register(T.Responder, wiring.responder, { owned: false });
38
+ if (wiring.permission !== undefined && !scope.hasLocal(T.PermissionOptions))
39
+ scope.register(T.PermissionOptions, wiring.permission);
40
+ if (wiring.steer !== undefined && !scope.hasLocal(T.Steer))
41
+ scope.register(T.Steer, wiring.steer, { owned: false });
42
+ if (wiring.background !== undefined && !scope.hasLocal(T.BackgroundSpawner))
43
+ scope.register(T.BackgroundSpawner, wiring.background, { owned: false });
44
+ }
45
+ /** `new Runner(...)` for tests: the wiring bag becomes a harness scope + a per-session hook. */
46
+ export function testRunner(options = {}) {
47
+ const { machine, store, events, tracing, responder, permission, capabilities, steer, background, eventPublication, logger, session, ...config } = options;
48
+ const wiring = { machine, store, events, tracing, responder, permission, capabilities, steer, background, eventPublication, logger };
49
+ return new Runner(testHarnessScope(wiring), {
50
+ ...config,
51
+ session: async (scope, ctx) => {
52
+ wireTestSession(scope, wiring);
53
+ const extra = session !== undefined ? await session(scope, ctx) : [];
54
+ return [...(capabilities ?? []), ...extra];
55
+ },
56
+ });
57
+ }
58
+ /** `Session.open(...)` for tests: the wiring bag becomes a session scope under a harness scope. */
59
+ export async function openTestSession(options = {}) {
60
+ const { sessionId, signal, parent, capabilities, preloadedLog, ...wiring } = options;
61
+ const scope = (parent ?? testHarnessScope(wiring)).child("session");
62
+ if (sessionId !== undefined)
63
+ scope.register(T.SessionId, sessionId);
64
+ if (signal !== undefined)
65
+ scope.register(T.HostSignal, signal, { owned: false });
66
+ wireTestSession(scope, wiring);
67
+ return Session.open(scope, {
68
+ ...(capabilities !== undefined ? { capabilities } : {}),
69
+ ...(preloadedLog !== undefined ? { preloadedLog } : {}),
70
+ });
71
+ }
72
+ /** A session scope wired from the bag, with the defaults `Session.open` would provide. */
73
+ export function testSessionScope(wiring = {}) {
74
+ const scope = testHarnessScope(wiring).child("session");
75
+ wireTestSession(scope, wiring);
76
+ scope.provide(T.SessionId, () => "s");
77
+ scope.provide(T.Events, () => new ListenerSink());
78
+ scope.provide(T.Steer, () => new SteerBus());
79
+ scope.provide(T.SessionSignal, () => new AbortController().signal);
80
+ if (!scope.hasLocal(T.Machine)) {
81
+ const factory = scope.get(T.MachineFactory);
82
+ if (factory !== undefined && typeof factory !== "function")
83
+ scope.register(T.Machine, factory, { owned: false });
84
+ }
85
+ scope.provide(T.Machine, () => new NullMachine());
86
+ scope.provide(T.SessionLog, (s) => () => readLog(s.get(T.Store) ?? s.get(T.StoreBackend)));
87
+ return scope;
88
+ }
89
+ export function testProvisionContext(wiring = {}) {
90
+ const scope = testSessionScope(wiring);
91
+ return { scope, sessionId: scope.require(T.SessionId), signal: scope.require(T.SessionSignal) };
92
+ }
93
+ export function testRunContext(wiring = {}) {
94
+ const base = testProvisionContext(wiring);
95
+ return {
96
+ ...base,
97
+ injection: new InjectionManager(),
98
+ gates: { compaction: [] },
99
+ controls: {
100
+ abort: () => undefined,
101
+ compact: () => Promise.reject(new Error("no compaction in a test run context")),
102
+ getContextBreakdown: () => undefined,
103
+ setModel: () => undefined,
104
+ setThinking: () => undefined,
105
+ },
106
+ };
107
+ }
108
+ /** Run a capability's provisions on a fresh session scope — what `Session.open` does for it. */
109
+ export async function openCapability(cap, wiring = {}) {
110
+ const ctx = testProvisionContext(wiring);
111
+ let service;
112
+ for (const provision of cap.provides ?? []) {
113
+ service = await provision.create(ctx);
114
+ ctx.scope.register(provision.token, service, provision.dispose !== undefined ? { dispose: provision.dispose } : {});
115
+ }
116
+ return { ctx, service, close: () => ctx.scope.close() };
117
+ }
118
+ //# sourceMappingURL=testing.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "operon-agents-core",
3
- "version": "0.1.0-alpha.2",
3
+ "version": "0.1.0-alpha.4",
4
4
  "description": "Internal engine for operon-agents. Prefer operon-agents for application code.",
5
5
  "type": "module",
6
6
  "engines": {