laohuang 0.4.2 → 0.5.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 (113) hide show
  1. package/README.md +10 -6
  2. package/dist/agent.d.ts +7 -27
  3. package/dist/agent.js +53 -567
  4. package/dist/agent.js.map +1 -1
  5. package/dist/capabilities.d.ts +19 -0
  6. package/dist/capabilities.js +29 -0
  7. package/dist/capabilities.js.map +1 -0
  8. package/dist/cli.d.ts +9 -6
  9. package/dist/cli.js +83 -70
  10. package/dist/cli.js.map +1 -1
  11. package/dist/commands.d.ts +20 -3
  12. package/dist/commands.js +39 -38
  13. package/dist/commands.js.map +1 -1
  14. package/dist/keybindings/default-keybindings.d.ts +2 -0
  15. package/dist/keybindings/default-keybindings.js +10 -0
  16. package/dist/keybindings/default-keybindings.js.map +1 -0
  17. package/dist/keybindings/hints.d.ts +3 -0
  18. package/dist/keybindings/hints.js +7 -0
  19. package/dist/keybindings/hints.js.map +1 -0
  20. package/dist/keybindings/key-id.d.ts +20 -0
  21. package/dist/keybindings/key-id.js +11 -0
  22. package/dist/keybindings/key-id.js.map +1 -0
  23. package/dist/keybindings/key-parser.d.ts +7 -0
  24. package/dist/keybindings/key-parser.js +92 -0
  25. package/dist/keybindings/key-parser.js.map +1 -0
  26. package/dist/keybindings/keybindings.d.ts +21 -0
  27. package/dist/keybindings/keybindings.js +65 -0
  28. package/dist/keybindings/keybindings.js.map +1 -0
  29. package/dist/routing.d.ts +2 -57
  30. package/dist/routing.js +3 -161
  31. package/dist/routing.js.map +1 -1
  32. package/dist/runtime/agent-step-runner.d.ts +51 -0
  33. package/dist/runtime/agent-step-runner.js +361 -0
  34. package/dist/runtime/agent-step-runner.js.map +1 -0
  35. package/dist/runtime/agent-turn-loop.d.ts +36 -0
  36. package/dist/runtime/agent-turn-loop.js +71 -0
  37. package/dist/runtime/agent-turn-loop.js.map +1 -0
  38. package/dist/runtime/guard-policy.d.ts +21 -0
  39. package/dist/runtime/guard-policy.js +93 -0
  40. package/dist/runtime/guard-policy.js.map +1 -0
  41. package/dist/runtime/history-committer.d.ts +34 -0
  42. package/dist/runtime/history-committer.js +77 -0
  43. package/dist/runtime/history-committer.js.map +1 -0
  44. package/dist/runtime/human-intent-router.d.ts +5 -0
  45. package/dist/runtime/human-intent-router.js +38 -0
  46. package/dist/runtime/human-intent-router.js.map +1 -0
  47. package/dist/runtime/model-runtime.d.ts +33 -0
  48. package/dist/runtime/model-runtime.js +70 -0
  49. package/dist/runtime/model-runtime.js.map +1 -0
  50. package/dist/runtime/queue-bridge.d.ts +11 -0
  51. package/dist/runtime/queue-bridge.js +2 -0
  52. package/dist/runtime/queue-bridge.js.map +1 -0
  53. package/dist/runtime/queue-dispatcher.d.ts +45 -0
  54. package/dist/runtime/queue-dispatcher.js +120 -0
  55. package/dist/runtime/queue-dispatcher.js.map +1 -0
  56. package/dist/runtime/runtime-events.d.ts +26 -0
  57. package/dist/runtime/runtime-events.js +21 -0
  58. package/dist/runtime/runtime-events.js.map +1 -0
  59. package/dist/runtime/session-action-protocol.d.ts +10 -0
  60. package/dist/runtime/session-action-protocol.js +64 -0
  61. package/dist/runtime/session-action-protocol.js.map +1 -0
  62. package/dist/runtime/session-action.d.ts +42 -0
  63. package/dist/runtime/session-action.js +3 -0
  64. package/dist/runtime/session-action.js.map +1 -0
  65. package/dist/runtime/task-lifecycle.d.ts +73 -0
  66. package/dist/runtime/task-lifecycle.js +267 -0
  67. package/dist/runtime/task-lifecycle.js.map +1 -0
  68. package/dist/runtime/tool-runtime.d.ts +33 -0
  69. package/dist/runtime/tool-runtime.js +89 -0
  70. package/dist/runtime/tool-runtime.js.map +1 -0
  71. package/dist/runtime/user-intent.d.ts +48 -0
  72. package/dist/runtime/user-intent.js +17 -0
  73. package/dist/runtime/user-intent.js.map +1 -0
  74. package/dist/session.d.ts +19 -9
  75. package/dist/session.js +119 -169
  76. package/dist/session.js.map +1 -1
  77. package/dist/terminal/editor.d.ts +16 -5
  78. package/dist/terminal/editor.js +99 -4
  79. package/dist/terminal/editor.js.map +1 -1
  80. package/dist/terminal/input.d.ts +2 -0
  81. package/dist/terminal/input.js +32 -7
  82. package/dist/terminal/input.js.map +1 -1
  83. package/dist/terminal/ui.d.ts +32 -21
  84. package/dist/terminal/ui.js +413 -252
  85. package/dist/terminal/ui.js.map +1 -1
  86. package/dist/tools.d.ts +7 -0
  87. package/dist/tools.js.map +1 -1
  88. package/dist/tui/components.d.ts +5 -0
  89. package/dist/tui/components.js +12 -0
  90. package/dist/tui/components.js.map +1 -0
  91. package/dist/tui/focus-manager.d.ts +7 -0
  92. package/dist/tui/focus-manager.js +13 -0
  93. package/dist/tui/focus-manager.js.map +1 -0
  94. package/dist/tui/overlay-manager.d.ts +12 -0
  95. package/dist/tui/overlay-manager.js +27 -0
  96. package/dist/tui/overlay-manager.js.map +1 -0
  97. package/dist/ui/display-actions.d.ts +23 -0
  98. package/dist/ui/display-actions.js +15 -0
  99. package/dist/ui/display-actions.js.map +1 -0
  100. package/dist/ui/display-policy.d.ts +38 -0
  101. package/dist/ui/display-policy.js +97 -0
  102. package/dist/ui/display-policy.js.map +1 -0
  103. package/dist/ui/frame-builder.d.ts +39 -0
  104. package/dist/ui/frame-builder.js +111 -0
  105. package/dist/ui/frame-builder.js.map +1 -0
  106. package/dist/ui/transcript-store.d.ts +35 -0
  107. package/dist/ui/transcript-store.js +172 -0
  108. package/dist/ui/transcript-store.js.map +1 -0
  109. package/dist/ui-state.js +6 -6
  110. package/dist/ui-state.js.map +1 -1
  111. package/dist/web.js +14 -1
  112. package/dist/web.js.map +1 -1
  113. package/package.json +2 -2
@@ -0,0 +1,77 @@
1
+ /** Commits canonical conversation history while preserving session atomicity. */
2
+ export class HistoryCommitter {
3
+ messages;
4
+ context;
5
+ cancelToken;
6
+ createCancelled;
7
+ constructor(options) {
8
+ this.messages = options.messages;
9
+ this.context = options.context;
10
+ this.cancelToken = options.cancelToken;
11
+ this.createCancelled = options.createCancelled;
12
+ }
13
+ commitInput(content) {
14
+ const message = { role: "user", content };
15
+ const commitInput = this.context?.commitInput;
16
+ if (typeof commitInput === "function") {
17
+ return this.commitContextMessage((append, rollback) => commitInput.call(this.context, append, rollback), message);
18
+ }
19
+ this.raiseIfCancelled();
20
+ this.messages.push(message);
21
+ return true;
22
+ }
23
+ commitPending(batch) {
24
+ const content = batch.content ?? "";
25
+ if (content === "") {
26
+ return true;
27
+ }
28
+ const message = { role: "user", content };
29
+ const commitPending = this.context?.commitPending;
30
+ if (typeof commitPending === "function") {
31
+ return this.commitContextMessage((append, rollback) => commitPending.call(this.context, batch, append, rollback), message);
32
+ }
33
+ this.raiseIfCancelled();
34
+ this.messages.push(message);
35
+ return true;
36
+ }
37
+ commitAssistant(message) {
38
+ const commitIfActive = this.context?.commitIfActive;
39
+ if (typeof commitIfActive === "function") {
40
+ return commitIfActive.call(this.context, () => {
41
+ this.messages.push(message);
42
+ });
43
+ }
44
+ this.raiseIfCancelled();
45
+ this.messages.push(message);
46
+ return true;
47
+ }
48
+ commitToolResults(toolCalls, toolResults) {
49
+ for (let index = 0; index < toolCalls.length; index += 1) {
50
+ this.messages.push({
51
+ role: "tool",
52
+ tool_call_id: toolCalls[index]?.id,
53
+ content: JSON.stringify(toolResults[index]),
54
+ });
55
+ }
56
+ }
57
+ snapshot() {
58
+ return [...this.messages];
59
+ }
60
+ commitContextMessage(commit, message) {
61
+ const append = () => {
62
+ this.messages.push(message);
63
+ };
64
+ const rollback = () => {
65
+ if (this.messages.at(-1) === message) {
66
+ this.messages.pop();
67
+ }
68
+ };
69
+ return Boolean(commit(append, rollback));
70
+ }
71
+ raiseIfCancelled() {
72
+ if (this.cancelToken !== null && this.cancelToken.isCancelled()) {
73
+ throw this.createCancelled(this.cancelToken.reason || "cancelled");
74
+ }
75
+ }
76
+ }
77
+ //# sourceMappingURL=history-committer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"history-committer.js","sourceRoot":"","sources":["../../src/runtime/history-committer.ts"],"names":[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AAC,QAAQ,CAAC,CAAC;IAC5B,CAAC;IAEO,oBAAoB,CAC1B,MAA6D,EAC7D,OAAuB;QAEvB,MAAM,MAAM,GAAG,GAAS,EAAE;YACxB,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAC9B,CAAC,CAAC;QACF,MAAM,QAAQ,GAAG,GAAS,EAAE;YAC1B,IAAI,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,KAAK,OAAO,EAAE,CAAC;gBACrC,IAAI,CAAC,QAAQ,CAAC,GAAG,EAAE,CAAC;YACtB,CAAC;QACH,CAAC,CAAC;QACF,OAAO,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC;IAC3C,CAAC;IAEO,gBAAgB;QACtB,IAAI,IAAI,CAAC,WAAW,KAAK,IAAI,IAAI,IAAI,CAAC,WAAW,CAAC,WAAW,EAAE,EAAE,CAAC;YAChE,MAAM,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,IAAI,WAAW,CAAC,CAAC;QACrE,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,5 @@
1
+ /** Convert user-facing intents into the session action protocol. */
2
+ import type { SessionState as SessionStateValue } from "../session.ts";
3
+ import type { UserIntent } from "./user-intent.ts";
4
+ import type { SessionAction } from "./session-action.ts";
5
+ export declare function routeHumanIntent(intent: UserIntent, state: SessionStateValue): SessionAction;
@@ -0,0 +1,38 @@
1
+ /** Convert user-facing intents into the session action protocol. */
2
+ import { shlexSplit } from "../commands.js";
3
+ import { makeAnswerAction, makeApprovalAction, makeCancelAction, makeCommandAction, makeExitAction, makePromptAction, makeSteerAction, makeFollowUpAction, } from "./session-action-protocol.js";
4
+ function commandAction(text, source) {
5
+ const [name, ...arguments_] = shlexSplit(text);
6
+ if (name === undefined) {
7
+ return makePromptAction(text, source);
8
+ }
9
+ if (name === "/exit" && arguments_.length === 0) {
10
+ return makeExitAction(source);
11
+ }
12
+ return makeCommandAction(name, arguments_, source, text);
13
+ }
14
+ export function routeHumanIntent(intent, state) {
15
+ switch (intent.type) {
16
+ case "prompt":
17
+ if (intent.text.startsWith("/")) {
18
+ return commandAction(intent.text, intent.source);
19
+ }
20
+ void state;
21
+ return makePromptAction(intent.text, intent.source);
22
+ case "command":
23
+ return makeCommandAction(intent.name, intent.arguments, intent.source);
24
+ case "steer":
25
+ return makeSteerAction(intent.text, intent.source);
26
+ case "follow_up":
27
+ return makeFollowUpAction(intent.text, intent.source);
28
+ case "cancel":
29
+ return makeCancelAction(intent.reason, intent.source);
30
+ case "approval":
31
+ return makeApprovalAction(intent.text, intent.source);
32
+ case "answer":
33
+ return makeAnswerAction(intent.text, intent.source);
34
+ case "exit":
35
+ return makeExitAction(intent.source);
36
+ }
37
+ }
38
+ //# sourceMappingURL=human-intent-router.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"human-intent-router.js","sourceRoot":"","sources":["../../src/runtime/human-intent-router.ts"],"names":[],"mappings":"AAAA,oEAAoE;AAEpE,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAI5C,OAAO,EACL,gBAAgB,EAChB,kBAAkB,EAClB,gBAAgB,EAChB,iBAAiB,EACjB,cAAc,EACd,gBAAgB,EAChB,eAAe,EACf,kBAAkB,GACnB,MAAM,8BAA8B,CAAC;AAEtC,SAAS,aAAa,CAAC,IAAY,EAAE,MAAc;IACjD,MAAM,CAAC,IAAI,EAAE,GAAG,UAAU,CAAC,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC;IAC/C,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;QACvB,OAAO,gBAAgB,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IACxC,CAAC;IACD,IAAI,IAAI,KAAK,OAAO,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAChD,OAAO,cAAc,CAAC,MAAM,CAAC,CAAC;IAChC,CAAC;IACD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type ChatClientLike, type ModelAdapter } from "../model-adapter.ts";
3
+ import { type AssembledToolCall } from "../model-stream.ts";
4
+ import type { ModelRuntimeEventHandler } from "./runtime-events.ts";
5
+ /** Provider-neutral input for one model completion. */
6
+ export interface ModelRuntimeRequest {
7
+ client: ChatClientLike;
8
+ model: string;
9
+ messages: Array<Record<string, unknown>>;
10
+ tools: Array<Record<string, unknown>>;
11
+ toolChoice?: string | Record<string, unknown> | null;
12
+ requestId?: string | undefined;
13
+ cancelToken?: CancelToken | null;
14
+ isRequestActive?: ((requestId: string) => boolean) | null;
15
+ onDelta?: ModelRuntimeEventHandler | null;
16
+ onRequestOpened?: (() => boolean | void) | null;
17
+ }
18
+ /** Fully validated model output, independent of a provider SDK response. */
19
+ export interface ModelRuntimeResult {
20
+ readonly requestId: string;
21
+ readonly content: string | null;
22
+ readonly reasoningContent: string | null;
23
+ readonly toolCalls: readonly AssembledToolCall[];
24
+ readonly finishReason: string;
25
+ readonly usage: unknown;
26
+ messageDict(): Record<string, unknown>;
27
+ }
28
+ /** Owns adapter invocation, cancellation preflight, and error normalization. */
29
+ export declare class ModelRuntime {
30
+ private readonly adapter;
31
+ constructor(adapter: ModelAdapter);
32
+ complete(request: ModelRuntimeRequest): Promise<ModelRuntimeResult>;
33
+ }
@@ -0,0 +1,70 @@
1
+ import { ModelError, modelErrorKind, } from "../model-adapter.js";
2
+ import { ModelStreamCancelled, ModelStreamError, } from "../model-stream.js";
3
+ /** Owns adapter invocation, cancellation preflight, and error normalization. */
4
+ export class ModelRuntime {
5
+ adapter;
6
+ constructor(adapter) {
7
+ this.adapter = adapter;
8
+ }
9
+ async complete(request) {
10
+ if (request.cancelToken?.isCancelled()) {
11
+ throw new ModelStreamCancelled(request.cancelToken.reason || "cancelled");
12
+ }
13
+ try {
14
+ const result = await this.adapter.complete(request.client, {
15
+ model: request.model,
16
+ messages: request.messages,
17
+ tools: request.tools,
18
+ toolChoice: request.toolChoice ?? null,
19
+ requestId: request.requestId,
20
+ cancelToken: request.cancelToken ?? null,
21
+ isRequestActive: request.isRequestActive ?? null,
22
+ onDelta: request.onDelta === undefined || request.onDelta === null
23
+ ? null
24
+ : (kind, payload) => request.onDelta?.(kind, payload),
25
+ onRequestOpened: request.onRequestOpened ?? null,
26
+ });
27
+ return toModelRuntimeResult(result);
28
+ }
29
+ catch (error) {
30
+ throw normalizeRuntimeError(error, request.cancelToken ?? null);
31
+ }
32
+ }
33
+ }
34
+ function toModelRuntimeResult(result) {
35
+ return {
36
+ requestId: result.requestId,
37
+ content: result.content,
38
+ reasoningContent: result.reasoningContent,
39
+ toolCalls: result.toolCalls,
40
+ finishReason: result.finishReason,
41
+ usage: result.usage,
42
+ messageDict: () => result.messageDict(),
43
+ };
44
+ }
45
+ function normalizeRuntimeError(error, cancelToken) {
46
+ if (error instanceof ModelStreamCancelled) {
47
+ return error;
48
+ }
49
+ if (cancelToken?.isCancelled()) {
50
+ return new ModelStreamCancelled(cancelToken.reason || "cancelled", { cause: error });
51
+ }
52
+ if (error instanceof ModelError) {
53
+ return error;
54
+ }
55
+ if (error instanceof ModelStreamError) {
56
+ return new ModelError(error.message, {
57
+ kind: modelErrorKind(error),
58
+ hadDelta: error.hadDelta,
59
+ cause: error,
60
+ });
61
+ }
62
+ return new ModelError(errorMessage(error), {
63
+ kind: modelErrorKind(error),
64
+ cause: error,
65
+ });
66
+ }
67
+ function errorMessage(error) {
68
+ return error instanceof Error ? error.message : String(error);
69
+ }
70
+ //# sourceMappingURL=model-runtime.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"model-runtime.js","sourceRoot":"","sources":["../../src/runtime/model-runtime.ts"],"names":[],"mappings":"AACA,OAAO,EACL,UAAU,EACV,cAAc,GAGf,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,oBAAoB,EACpB,gBAAgB,GAGjB,MAAM,oBAAoB,CAAC;AA4B5B,gFAAgF;AAChF,MAAM,OAAO,YAAY;IACN,OAAO,CAAe;IAEvC,YAAY,OAAqB;QAC/B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
+ export interface QueueInputBatch {
3
+ readonly content: string;
4
+ readonly eventIds: readonly string[];
5
+ }
6
+ /** Queue operations needed by the outer agent turn loop. */
7
+ export interface QueueBridge {
8
+ drainPending(taskId: string): QueueInputBatch | null;
9
+ acknowledgeClaimedInput(taskId: string, eventIds: readonly string[]): boolean;
10
+ preserveTaskInputs(taskId: string, reason: string): number;
11
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=queue-bridge.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"queue-bridge.js","sourceRoot":"","sources":["../../src/runtime/queue-bridge.ts"],"names":[],"mappings":""}
@@ -0,0 +1,45 @@
1
+ /** Queue placement policy for already-routed session actions. */
2
+ import { DeadLetterQueue, HeldQueue, PendingQueue, type RoutedEvent } from "../routing.ts";
3
+ import type { SessionAction } from "./session-action.ts";
4
+ export declare const QueueDispatchStatus: {
5
+ readonly StartNow: "start_now";
6
+ readonly Pending: "pending";
7
+ readonly Held: "held";
8
+ readonly CancelNow: "cancel_now";
9
+ readonly DeadLetter: "dead_letter";
10
+ readonly Ignored: "ignored";
11
+ };
12
+ export type QueueDispatchStatus = (typeof QueueDispatchStatus)[keyof typeof QueueDispatchStatus];
13
+ export interface QueueDispatchResult {
14
+ readonly status: QueueDispatchStatus;
15
+ readonly actionId: string;
16
+ readonly position: number | null;
17
+ readonly reason: string | null;
18
+ }
19
+ export type QueueRuntimeState = "idle" | "running" | "cancelling" | "stopped";
20
+ export interface QueueRuntimeSnapshot {
21
+ readonly state: QueueRuntimeState;
22
+ }
23
+ export interface QueueDispatcherOptions {
24
+ pending?: PendingQueue;
25
+ held?: HeldQueue;
26
+ deadLetters?: DeadLetterQueue;
27
+ }
28
+ /** Places user actions without changing the router's route decisions. */
29
+ export declare class QueueDispatcher {
30
+ readonly pending: PendingQueue;
31
+ readonly held: HeldQueue;
32
+ readonly deadLetters: DeadLetterQueue;
33
+ constructor(options?: QueueDispatcherOptions);
34
+ dispatch(action: SessionAction, snapshot: QueueRuntimeSnapshot, routed: RoutedEvent): QueueDispatchResult;
35
+ private placementFor;
36
+ /** Queue APIs validate destination; preserve all other router metadata. */
37
+ private withPlacement;
38
+ private enqueuePending;
39
+ private enqueueHeld;
40
+ private deadLetterOverflow;
41
+ }
42
+ export declare function makeQueueDispatchResult(status: QueueDispatchStatus, actionId: string, options?: {
43
+ position?: number;
44
+ reason?: string;
45
+ }): QueueDispatchResult;
@@ -0,0 +1,120 @@
1
+ /** Queue placement policy for already-routed session actions. */
2
+ import { DeadLetterQueue, HeldQueue, PendingQueue, QueueOverflowError, } from "../routing.js";
3
+ export const QueueDispatchStatus = {
4
+ StartNow: "start_now",
5
+ Pending: "pending",
6
+ Held: "held",
7
+ CancelNow: "cancel_now",
8
+ DeadLetter: "dead_letter",
9
+ Ignored: "ignored",
10
+ };
11
+ /** Places user actions without changing the router's route decisions. */
12
+ export class QueueDispatcher {
13
+ pending;
14
+ held;
15
+ deadLetters;
16
+ constructor(options = {}) {
17
+ this.pending = options.pending ?? new PendingQueue();
18
+ this.held = options.held ?? new HeldQueue();
19
+ this.deadLetters = options.deadLetters ?? new DeadLetterQueue();
20
+ }
21
+ dispatch(action, snapshot, routed) {
22
+ if (routed.decision.destination === "drop") {
23
+ this.deadLetters.put(routed.event, routed.decision.reason);
24
+ return makeQueueDispatchResult(QueueDispatchStatus.DeadLetter, action.id, {
25
+ reason: routed.decision.reason,
26
+ });
27
+ }
28
+ if (routed.decision.destination === "held" &&
29
+ routed.decision.timing === "after_cancel") {
30
+ return this.enqueueHeld(action.id, routed);
31
+ }
32
+ const placement = this.placementFor(action, snapshot);
33
+ if (placement === QueueDispatchStatus.StartNow) {
34
+ return makeQueueDispatchResult(QueueDispatchStatus.StartNow, action.id);
35
+ }
36
+ if (placement === QueueDispatchStatus.Pending) {
37
+ return this.enqueuePending(action.id, this.withPlacement(routed, "pending"));
38
+ }
39
+ if (placement === QueueDispatchStatus.Held) {
40
+ return this.enqueueHeld(action.id, this.withPlacement(routed, "held"));
41
+ }
42
+ if (placement === QueueDispatchStatus.CancelNow) {
43
+ return makeQueueDispatchResult(QueueDispatchStatus.CancelNow, action.id);
44
+ }
45
+ const destination = routed.decision.destination;
46
+ if (destination === "new_task" && snapshot.state === "idle") {
47
+ return makeQueueDispatchResult(QueueDispatchStatus.StartNow, action.id);
48
+ }
49
+ if (destination === "pending") {
50
+ return this.enqueuePending(action.id, routed);
51
+ }
52
+ if (destination === "held") {
53
+ return this.enqueueHeld(action.id, routed);
54
+ }
55
+ return makeQueueDispatchResult(QueueDispatchStatus.Ignored, action.id);
56
+ }
57
+ placementFor(action, snapshot) {
58
+ if (action.type === "cancel") {
59
+ return QueueDispatchStatus.CancelNow;
60
+ }
61
+ if (action.type === "prompt" && snapshot.state === "idle") {
62
+ return QueueDispatchStatus.StartNow;
63
+ }
64
+ if (snapshot.state === "running" &&
65
+ (action.type === "steer" || action.type === "follow_up")) {
66
+ return QueueDispatchStatus.Pending;
67
+ }
68
+ if (action.type === "prompt" && snapshot.state === "cancelling") {
69
+ return QueueDispatchStatus.Held;
70
+ }
71
+ return null;
72
+ }
73
+ /** Queue APIs validate destination; preserve all other router metadata. */
74
+ withPlacement(routed, destination) {
75
+ return {
76
+ event: routed.event,
77
+ decision: { ...routed.decision, destination },
78
+ };
79
+ }
80
+ enqueuePending(actionId, routed) {
81
+ try {
82
+ this.pending.put(routed);
83
+ return makeQueueDispatchResult(QueueDispatchStatus.Pending, actionId, {
84
+ position: this.pending.size,
85
+ });
86
+ }
87
+ catch (error) {
88
+ return this.deadLetterOverflow(actionId, routed, error);
89
+ }
90
+ }
91
+ enqueueHeld(actionId, routed) {
92
+ try {
93
+ this.held.put(routed);
94
+ return makeQueueDispatchResult(QueueDispatchStatus.Held, actionId, {
95
+ position: this.held.size,
96
+ });
97
+ }
98
+ catch (error) {
99
+ return this.deadLetterOverflow(actionId, routed, error);
100
+ }
101
+ }
102
+ deadLetterOverflow(actionId, routed, error) {
103
+ if (!(error instanceof QueueOverflowError)) {
104
+ throw error;
105
+ }
106
+ this.deadLetters.put(routed.event, error.message);
107
+ return makeQueueDispatchResult(QueueDispatchStatus.DeadLetter, actionId, {
108
+ reason: error.message,
109
+ });
110
+ }
111
+ }
112
+ export function makeQueueDispatchResult(status, actionId, options = {}) {
113
+ return {
114
+ status,
115
+ actionId,
116
+ position: options.position ?? null,
117
+ reason: options.reason ?? null,
118
+ };
119
+ }
120
+ //# sourceMappingURL=queue-dispatcher.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"queue-dispatcher.js","sourceRoot":"","sources":["../../src/runtime/queue-dispatcher.ts"],"names":[],"mappings":"AAAA,iEAAiE;AAEjE,OAAO,EACL,eAAe,EACf,SAAS,EACT,YAAY,EACZ,kBAAkB,GAEnB,MAAM,eAAe,CAAC;AAGvB,MAAM,CAAC,MAAM,mBAAmB,GAAG;IACjC,QAAQ,EAAE,WAAW;IACrB,OAAO,EAAE,SAAS;IAClB,IAAI,EAAE,MAAM;IACZ,SAAS,EAAE,YAAY;IACvB,UAAU,EAAE,aAAa;IACzB,OAAO,EAAE,SAAS;CACV,CAAC;AAwBX,yEAAyE;AACzE,MAAM,OAAO,eAAe;IACjB,OAAO,CAAe;IACtB,IAAI,CAAY;IAChB,WAAW,CAAkB;IAEtC,YAAY,UAAkC,EAAE;QAC9C,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,IAAI,IAAI,YAAY,EAAE,CAAC;QACrD,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,IAAI,IAAI,SAAS,EAAE,CAAC;QAC5C,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC,WAAW,IAAI,IAAI,eAAe,EAAE,CAAC;IAClE,CAAC;IAED,QAAQ,CACN,MAAqB,EACrB,QAA8B,EAC9B,MAAmB;QAEnB,IAAI,MAAM,CAAC,QAAQ,CAAC,WAAW,KAAK,MAAM,EAAE,CAAC;YAC3C,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,MAAM,CAAC,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AAmB,CAAC,UAAU,EAAE,QAAQ,EAAE;YACvE,MAAM,EAAE,KAAK,CAAC,OAAO;SACtB,CAAC,CAAC;IACL,CAAC;CACF;AAED,MAAM,UAAU,uBAAuB,CACrC,MAA2B,EAC3B,QAAgB,EAChB,UAAkD,EAAE;IAEpD,OAAO;QACL,MAAM;QACN,QAAQ;QACR,QAAQ,EAAE,OAAO,CAAC,QAAQ,IAAI,IAAI;QAClC,MAAM,EAAE,OAAO,CAAC,MAAM,IAAI,IAAI;KAC/B,CAAC;AACJ,CAAC"}
@@ -0,0 +1,26 @@
1
+ /** Runtime event contracts shared by producers and projections. */
2
+ export declare const RuntimeEventKind: {
3
+ readonly ActionReceived: "action.received";
4
+ readonly TaskStarted: "task.started";
5
+ readonly TaskStateChanged: "task.state_changed";
6
+ readonly TaskCompleted: "task.completed";
7
+ readonly TaskFailed: "task.failed";
8
+ readonly TaskCancelled: "task.cancelled";
9
+ readonly Display: "display.action";
10
+ };
11
+ export type RuntimeEventKind = (typeof RuntimeEventKind)[keyof typeof RuntimeEventKind];
12
+ /** Model-stream event names forwarded through the runtime boundary. */
13
+ export type ModelRuntimeEventType = "model_text_delta" | "model_reasoning_delta" | "model_tool_call_delta" | "model_response_validating";
14
+ export type ModelRuntimeEventHandler = (eventType: ModelRuntimeEventType, payload: Record<string, unknown>) => void;
15
+ export interface RuntimeEvent<K extends RuntimeEventKind = RuntimeEventKind, P = unknown> {
16
+ readonly id: string;
17
+ readonly kind: K;
18
+ readonly timestamp: number;
19
+ readonly taskId: string | null;
20
+ readonly payload: P;
21
+ }
22
+ export declare function makeRuntimeEvent<K extends RuntimeEventKind, P>(kind: K, payload: P, options?: {
23
+ id?: string;
24
+ taskId?: string | null;
25
+ timestamp?: number;
26
+ }): RuntimeEvent<K, P>;
@@ -0,0 +1,21 @@
1
+ /** Runtime event contracts shared by producers and projections. */
2
+ import { randomUUID } from "node:crypto";
3
+ export const RuntimeEventKind = {
4
+ ActionReceived: "action.received",
5
+ TaskStarted: "task.started",
6
+ TaskStateChanged: "task.state_changed",
7
+ TaskCompleted: "task.completed",
8
+ TaskFailed: "task.failed",
9
+ TaskCancelled: "task.cancelled",
10
+ Display: "display.action",
11
+ };
12
+ export function makeRuntimeEvent(kind, payload, options = {}) {
13
+ return {
14
+ id: options.id ?? `event_${randomUUID()}`,
15
+ kind,
16
+ timestamp: options.timestamp ?? Date.now(),
17
+ taskId: options.taskId ?? null,
18
+ payload,
19
+ };
20
+ }
21
+ //# sourceMappingURL=runtime-events.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime-events.js","sourceRoot":"","sources":["../../src/runtime/runtime-events.ts"],"names":[],"mappings":"AAAA,mEAAmE;AAEnE,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC9B,cAAc,EAAE,iBAAiB;IACjC,WAAW,EAAE,cAAc;IAC3B,gBAAgB,EAAE,oBAAoB;IACtC,aAAa,EAAE,gBAAgB;IAC/B,UAAU,EAAE,aAAa;IACzB,aAAa,EAAE,gBAAgB;IAC/B,OAAO,EAAE,gBAAgB;CACjB,CAAC;AA4BX,MAAM,UAAU,gBAAgB,CAC9B,IAAO,EACP,OAAU,EACV,UAAuE,EAAE;IAEzE,OAAO;QACL,EAAE,EAAE,OAAO,CAAC,EAAE,IAAI,SAAS,UAAU,EAAE,EAAE;QACzC,IAAI;QACJ,SAAS,EAAE,OAAO,CAAC,SAAS,IAAI,IAAI,CAAC,GAAG,EAAE;QAC1C,MAAM,EAAE,OAAO,CAAC,MAAM,IAAI,IAAI;QAC9B,OAAO;KACR,CAAC;AACJ,CAAC"}
@@ -0,0 +1,10 @@
1
+ import type { AnswerAction, ApprovalAction, CancelAction, CommandAction, ExitAction, FollowUpAction, PromptAction, SessionAction, SteerAction } from "./session-action.ts";
2
+ export declare function makePromptAction(text: string, source: string): PromptAction;
3
+ export declare function makeCommandAction(name: string, arguments_?: readonly string[], source?: string, text?: string): CommandAction;
4
+ export declare function makeSteerAction(text: string, source: string): SteerAction;
5
+ export declare function makeFollowUpAction(text: string, source: string): FollowUpAction;
6
+ export declare function makeCancelAction(reason?: string, source?: string): CancelAction;
7
+ export declare function makeApprovalAction(text: string, source: string): ApprovalAction;
8
+ export declare function makeAnswerAction(text: string, source: string): AnswerAction;
9
+ export declare function makeExitAction(source?: string): ExitAction;
10
+ export declare function isSessionAction(value: unknown): value is SessionAction;
@@ -0,0 +1,64 @@
1
+ import { randomUUID } from "node:crypto";
2
+ function actionId() {
3
+ return `action_${randomUUID()}`;
4
+ }
5
+ export function makePromptAction(text, source) {
6
+ return { id: actionId(), type: "prompt", text, source };
7
+ }
8
+ export function makeCommandAction(name, arguments_ = [], source = "command", text = [name, ...arguments_].join(" ")) {
9
+ return {
10
+ id: actionId(),
11
+ type: "command",
12
+ name,
13
+ arguments: [...arguments_],
14
+ source,
15
+ text,
16
+ };
17
+ }
18
+ export function makeSteerAction(text, source) {
19
+ return { id: actionId(), type: "steer", text, source };
20
+ }
21
+ export function makeFollowUpAction(text, source) {
22
+ return { id: actionId(), type: "follow_up", text, source };
23
+ }
24
+ export function makeCancelAction(reason = "cancelled", source = "user") {
25
+ return { id: actionId(), type: "cancel", reason, source };
26
+ }
27
+ export function makeApprovalAction(text, source) {
28
+ return { id: actionId(), type: "approval", text, source };
29
+ }
30
+ export function makeAnswerAction(text, source) {
31
+ return { id: actionId(), type: "answer", text, source };
32
+ }
33
+ export function makeExitAction(source = "user") {
34
+ return { id: actionId(), type: "exit", source };
35
+ }
36
+ export function isSessionAction(value) {
37
+ if (typeof value !== "object" || value === null) {
38
+ return false;
39
+ }
40
+ const action = value;
41
+ if (typeof action.id !== "string" || typeof action.source !== "string") {
42
+ return false;
43
+ }
44
+ switch (action.type) {
45
+ case "prompt":
46
+ case "steer":
47
+ case "follow_up":
48
+ case "approval":
49
+ case "answer":
50
+ return typeof action.text === "string";
51
+ case "command":
52
+ return (typeof action.name === "string" &&
53
+ Array.isArray(action.arguments) &&
54
+ action.arguments.every((item) => typeof item === "string") &&
55
+ (action.text === undefined || typeof action.text === "string"));
56
+ case "cancel":
57
+ return typeof action.reason === "string";
58
+ case "exit":
59
+ return true;
60
+ default:
61
+ return false;
62
+ }
63
+ }
64
+ //# sourceMappingURL=session-action-protocol.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"session-action-protocol.js","sourceRoot":"","sources":["../../src/runtime/session-action-protocol.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAczC,SAAS,QAAQ;IACf,OAAO,UAAU,UAAU,EAAE,EAAE,CAAC;AAClC,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,IAAY,EAAE,MAAc;IAC3D,OAAO,EAAE,EAAE,EAAE,QAAQ,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;AAC1D,CAAC;AAED,MAAM,UAAU,iBAAiB,CAC/B,IAAY,EACZ,aAAgC,EAAE,EAClC,MAAM,GAAG,SAAS,EAClB,IAAI,GAAG,CAAC,IAAI,EAAE,GAAG,UAAU,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC;IAEtC,OAAO;QACL,EAAE,EAAE,QAAQ,EAAE;QACd,IAAI,EAAE,SAAS;QACf,IAAI;QACJ,SAAS,EAAE,CAAC,GAAG,UAAU,CAAC;QAC1B,MAAM;QACN,IAAI;KACL,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,IAAY,EAAE,MAAc;IAC1D,OAAO,EAAE,EAAE,EAAE,QAAQ,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;AACzD,CAAC;AAED,MAAM,UAAU,kBAAkB,CAChC,IAAY,EACZ,MAAc;IAEd,OAAO,EAAE,EAAE,EAAE,QAAQ,EAAE,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;AA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AS;YACZ,OAAO,CACL,OAAO,MAAM,CAAC,IAAI,KAAK,QAAQ;gBAC/B,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,SAAS,CAAC;gBAC/B,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,OAAO,IAAI,KAAK,QAAQ,CAAC;gBAC1D,CAAC,MAAM,CAAC,IAAI,KAAK,SAAS,IAAI,OAAO,MAAM,CAAC,IAAI,KAAK,QAAQ,CAAC,CAC/D,CAAC;QACJ,KAAK,QAAQ;YACX,OAAO,OAAO,MAAM,CAAC,MAAM,KAAK,QAAQ,CAAC;QAC3C,KAAK,MAAM;YACT,OAAO,IAAI,CAAC;QACd;YACE,OAAO,KAAK,CAAC;IACjB,CAAC;AACH,CAAC"}
@@ -0,0 +1,42 @@
1
+ /** Actions accepted by a runtime session after intent routing. */
2
+ export interface SessionActionBase {
3
+ readonly id: string;
4
+ readonly source: string;
5
+ }
6
+ export interface PromptAction extends SessionActionBase {
7
+ readonly type: "prompt";
8
+ readonly text: string;
9
+ }
10
+ export interface CommandAction extends SessionActionBase {
11
+ readonly type: "command";
12
+ readonly name: string;
13
+ readonly arguments: readonly string[];
14
+ /** Original command text, retained so quoted arguments survive dispatch. */
15
+ readonly text?: string;
16
+ }
17
+ export interface SteerAction extends SessionActionBase {
18
+ readonly type: "steer";
19
+ readonly text: string;
20
+ }
21
+ export interface FollowUpAction extends SessionActionBase {
22
+ readonly type: "follow_up";
23
+ readonly text: string;
24
+ }
25
+ export interface CancelAction extends SessionActionBase {
26
+ readonly type: "cancel";
27
+ readonly reason: string;
28
+ }
29
+ /** Compatibility shape until approvals have a dedicated runtime path. */
30
+ export interface ApprovalAction extends SessionActionBase {
31
+ readonly type: "approval";
32
+ readonly text: string;
33
+ }
34
+ /** Compatibility shape until answers have a dedicated runtime path. */
35
+ export interface AnswerAction extends SessionActionBase {
36
+ readonly type: "answer";
37
+ readonly text: string;
38
+ }
39
+ export interface ExitAction extends SessionActionBase {
40
+ readonly type: "exit";
41
+ }
42
+ export type SessionAction = PromptAction | CommandAction | SteerAction | FollowUpAction | CancelAction | ApprovalAction | AnswerAction | ExitAction;
@@ -0,0 +1,3 @@
1
+ /** Actions accepted by a runtime session after intent routing. */
2
+ export {};
3
+ //# sourceMappingURL=session-action.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"session-action.js","sourceRoot":"","sources":["../../src/runtime/session-action.ts"],"names":[],"mappings":"AAAA,kEAAkE"}