agent-world 0.13.0 → 0.15.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.
- package/README.md +90 -17
- package/dist/cli/commands.d.ts +7 -1
- package/dist/cli/commands.js +27 -10
- package/dist/cli/hitl.d.ts +4 -1
- package/dist/cli/hitl.js +55 -20
- package/dist/cli/index.js +249 -97
- package/dist/cli/system-events.d.ts +27 -0
- package/dist/cli/system-events.js +63 -0
- package/dist/core/activity-tracker.d.ts +26 -0
- package/dist/core/activity-tracker.d.ts.map +1 -1
- package/dist/core/activity-tracker.js +21 -4
- package/dist/core/activity-tracker.js.map +1 -1
- package/dist/core/anthropic-direct.d.ts +2 -0
- package/dist/core/anthropic-direct.d.ts.map +1 -1
- package/dist/core/anthropic-direct.js +43 -1
- package/dist/core/anthropic-direct.js.map +1 -1
- package/dist/core/chat-constants.d.ts +12 -0
- package/dist/core/chat-constants.d.ts.map +1 -1
- package/dist/core/chat-constants.js +5 -0
- package/dist/core/chat-constants.js.map +1 -1
- package/dist/core/create-agent-tool.d.ts +5 -0
- package/dist/core/create-agent-tool.d.ts.map +1 -1
- package/dist/core/create-agent-tool.js +57 -34
- package/dist/core/create-agent-tool.js.map +1 -1
- package/dist/core/events/index.d.ts +5 -2
- package/dist/core/events/index.d.ts.map +1 -1
- package/dist/core/events/index.js +5 -2
- package/dist/core/events/index.js.map +1 -1
- package/dist/core/events/memory-manager.d.ts +26 -1
- package/dist/core/events/memory-manager.d.ts.map +1 -1
- package/dist/core/events/memory-manager.js +877 -72
- package/dist/core/events/memory-manager.js.map +1 -1
- package/dist/core/events/orchestrator.d.ts +8 -0
- package/dist/core/events/orchestrator.d.ts.map +1 -1
- package/dist/core/events/orchestrator.js +203 -36
- package/dist/core/events/orchestrator.js.map +1 -1
- package/dist/core/events/persistence.d.ts +21 -14
- package/dist/core/events/persistence.d.ts.map +1 -1
- package/dist/core/events/persistence.js +100 -35
- package/dist/core/events/persistence.js.map +1 -1
- package/dist/core/events/publishers.d.ts +13 -7
- package/dist/core/events/publishers.d.ts.map +1 -1
- package/dist/core/events/publishers.js +53 -37
- package/dist/core/events/publishers.js.map +1 -1
- package/dist/core/events/subscribers.d.ts +17 -14
- package/dist/core/events/subscribers.d.ts.map +1 -1
- package/dist/core/events/subscribers.js +61 -148
- package/dist/core/events/subscribers.js.map +1 -1
- package/dist/core/events/title-scheduler.d.ts +27 -0
- package/dist/core/events/title-scheduler.d.ts.map +1 -0
- package/dist/core/events/title-scheduler.js +135 -0
- package/dist/core/events/title-scheduler.js.map +1 -0
- package/dist/core/events/tool-bridge-logging.d.ts +4 -1
- package/dist/core/events/tool-bridge-logging.d.ts.map +1 -1
- package/dist/core/events/tool-bridge-logging.js +112 -13
- package/dist/core/events/tool-bridge-logging.js.map +1 -1
- package/dist/core/events-metadata.d.ts.map +1 -1
- package/dist/core/events-metadata.js +8 -4
- package/dist/core/events-metadata.js.map +1 -1
- package/dist/core/export.d.ts +1 -1
- package/dist/core/export.d.ts.map +1 -1
- package/dist/core/export.js +2 -15
- package/dist/core/export.js.map +1 -1
- package/dist/core/feature-path-logging.d.ts +50 -0
- package/dist/core/feature-path-logging.d.ts.map +1 -0
- package/dist/core/feature-path-logging.js +130 -0
- package/dist/core/feature-path-logging.js.map +1 -0
- package/dist/core/file-tools.d.ts +57 -1
- package/dist/core/file-tools.d.ts.map +1 -1
- package/dist/core/file-tools.js +329 -29
- package/dist/core/file-tools.js.map +1 -1
- package/dist/core/google-direct.d.ts +6 -1
- package/dist/core/google-direct.d.ts.map +1 -1
- package/dist/core/google-direct.js +76 -7
- package/dist/core/google-direct.js.map +1 -1
- package/dist/core/heartbeat.d.ts +34 -0
- package/dist/core/heartbeat.d.ts.map +1 -0
- package/dist/core/heartbeat.js +153 -0
- package/dist/core/heartbeat.js.map +1 -0
- package/dist/core/hitl-tool.d.ts +6 -12
- package/dist/core/hitl-tool.d.ts.map +1 -1
- package/dist/core/hitl-tool.js +66 -88
- package/dist/core/hitl-tool.js.map +1 -1
- package/dist/core/hitl.d.ts +61 -4
- package/dist/core/hitl.d.ts.map +1 -1
- package/dist/core/hitl.js +324 -60
- package/dist/core/hitl.js.map +1 -1
- package/dist/core/index.d.ts +11 -7
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +10 -6
- package/dist/core/index.js.map +1 -1
- package/dist/core/llm-manager.d.ts +15 -0
- package/dist/core/llm-manager.d.ts.map +1 -1
- package/dist/core/llm-manager.js +325 -40
- package/dist/core/llm-manager.js.map +1 -1
- package/dist/core/load-skill-tool.d.ts +36 -3
- package/dist/core/load-skill-tool.d.ts.map +1 -1
- package/dist/core/load-skill-tool.js +807 -93
- package/dist/core/load-skill-tool.js.map +1 -1
- package/dist/core/logger.d.ts +14 -0
- package/dist/core/logger.d.ts.map +1 -1
- package/dist/core/logger.js +15 -0
- package/dist/core/logger.js.map +1 -1
- package/dist/core/managers.d.ts +18 -50
- package/dist/core/managers.d.ts.map +1 -1
- package/dist/core/managers.js +340 -502
- package/dist/core/managers.js.map +1 -1
- package/dist/core/mcp-server-registry.d.ts +16 -1
- package/dist/core/mcp-server-registry.d.ts.map +1 -1
- package/dist/core/mcp-server-registry.js +162 -12
- package/dist/core/mcp-server-registry.js.map +1 -1
- package/dist/core/message-cutoff.d.ts +29 -0
- package/dist/core/message-cutoff.d.ts.map +1 -0
- package/dist/core/message-cutoff.js +63 -0
- package/dist/core/message-cutoff.js.map +1 -0
- package/dist/core/message-edit-manager.d.ts +54 -0
- package/dist/core/message-edit-manager.d.ts.map +1 -0
- package/dist/core/message-edit-manager.js +602 -0
- package/dist/core/message-edit-manager.js.map +1 -0
- package/dist/core/message-prep.d.ts +2 -0
- package/dist/core/message-prep.d.ts.map +1 -1
- package/dist/core/message-prep.js +39 -12
- package/dist/core/message-prep.js.map +1 -1
- package/dist/core/message-processing-control.d.ts +1 -0
- package/dist/core/message-processing-control.d.ts.map +1 -1
- package/dist/core/message-processing-control.js +23 -6
- package/dist/core/message-processing-control.js.map +1 -1
- package/dist/core/openai-direct.d.ts +9 -3
- package/dist/core/openai-direct.d.ts.map +1 -1
- package/dist/core/openai-direct.js +267 -33
- package/dist/core/openai-direct.js.map +1 -1
- package/dist/core/optional-tracers/opik-runtime.d.ts +32 -0
- package/dist/core/optional-tracers/opik-runtime.d.ts.map +1 -0
- package/dist/core/optional-tracers/opik-runtime.js +141 -0
- package/dist/core/optional-tracers/opik-runtime.js.map +1 -0
- package/dist/core/queue-manager.d.ts +84 -0
- package/dist/core/queue-manager.d.ts.map +1 -0
- package/dist/core/queue-manager.js +814 -0
- package/dist/core/queue-manager.js.map +1 -0
- package/dist/core/reasoning-controls.d.ts +30 -0
- package/dist/core/reasoning-controls.d.ts.map +1 -0
- package/dist/core/reasoning-controls.js +118 -0
- package/dist/core/reasoning-controls.js.map +1 -0
- package/dist/core/reliability-config.d.ts +82 -0
- package/dist/core/reliability-config.d.ts.map +1 -0
- package/dist/core/reliability-config.js +106 -0
- package/dist/core/reliability-config.js.map +1 -0
- package/dist/core/reliability-runtime.d.ts +53 -0
- package/dist/core/reliability-runtime.d.ts.map +1 -0
- package/dist/core/reliability-runtime.js +92 -0
- package/dist/core/reliability-runtime.js.map +1 -0
- package/dist/core/security/guardrails.d.ts +21 -0
- package/dist/core/security/guardrails.d.ts.map +1 -0
- package/dist/core/security/guardrails.js +111 -0
- package/dist/core/security/guardrails.js.map +1 -0
- package/dist/core/send-message-tool.d.ts +79 -0
- package/dist/core/send-message-tool.d.ts.map +1 -0
- package/dist/core/send-message-tool.js +222 -0
- package/dist/core/send-message-tool.js.map +1 -0
- package/dist/core/shell-cmd-tool.d.ts +82 -1
- package/dist/core/shell-cmd-tool.d.ts.map +1 -1
- package/dist/core/shell-cmd-tool.js +854 -42
- package/dist/core/shell-cmd-tool.js.map +1 -1
- package/dist/core/skill-registry.d.ts +2 -0
- package/dist/core/skill-registry.d.ts.map +1 -1
- package/dist/core/skill-registry.js +52 -2
- package/dist/core/skill-registry.js.map +1 -1
- package/dist/core/storage/eventStorage/fileEventStorage.d.ts +5 -0
- package/dist/core/storage/eventStorage/fileEventStorage.d.ts.map +1 -1
- package/dist/core/storage/eventStorage/fileEventStorage.js +61 -0
- package/dist/core/storage/eventStorage/fileEventStorage.js.map +1 -1
- package/dist/core/storage/eventStorage/memoryEventStorage.d.ts +5 -0
- package/dist/core/storage/eventStorage/memoryEventStorage.d.ts.map +1 -1
- package/dist/core/storage/eventStorage/memoryEventStorage.js +34 -0
- package/dist/core/storage/eventStorage/memoryEventStorage.js.map +1 -1
- package/dist/core/storage/eventStorage/sqliteEventStorage.d.ts +1 -0
- package/dist/core/storage/eventStorage/sqliteEventStorage.d.ts.map +1 -1
- package/dist/core/storage/eventStorage/sqliteEventStorage.js +19 -2
- package/dist/core/storage/eventStorage/sqliteEventStorage.js.map +1 -1
- package/dist/core/storage/eventStorage/types.d.ts +6 -0
- package/dist/core/storage/eventStorage/types.d.ts.map +1 -1
- package/dist/core/storage/eventStorage/types.js +1 -0
- package/dist/core/storage/eventStorage/types.js.map +1 -1
- package/dist/core/storage/eventStorage/validation.d.ts.map +1 -1
- package/dist/core/storage/eventStorage/validation.js +2 -1
- package/dist/core/storage/eventStorage/validation.js.map +1 -1
- package/dist/core/storage/github-world-import.d.ts +84 -0
- package/dist/core/storage/github-world-import.d.ts.map +1 -0
- package/dist/core/storage/github-world-import.js +365 -0
- package/dist/core/storage/github-world-import.js.map +1 -0
- package/dist/core/storage/memory-storage.d.ts +19 -8
- package/dist/core/storage/memory-storage.d.ts.map +1 -1
- package/dist/core/storage/memory-storage.js +147 -49
- package/dist/core/storage/memory-storage.js.map +1 -1
- package/dist/core/storage/queue-storage.d.ts +1 -0
- package/dist/core/storage/queue-storage.d.ts.map +1 -1
- package/dist/core/storage/queue-storage.js +3 -2
- package/dist/core/storage/queue-storage.js.map +1 -1
- package/dist/core/storage/sqlite-storage.d.ts +14 -9
- package/dist/core/storage/sqlite-storage.d.ts.map +1 -1
- package/dist/core/storage/sqlite-storage.js +131 -154
- package/dist/core/storage/sqlite-storage.js.map +1 -1
- package/dist/core/storage/storage-factory.d.ts +3 -0
- package/dist/core/storage/storage-factory.d.ts.map +1 -1
- package/dist/core/storage/storage-factory.js +175 -89
- package/dist/core/storage/storage-factory.js.map +1 -1
- package/dist/core/storage/world-storage.d.ts +1 -1
- package/dist/core/storage/world-storage.d.ts.map +1 -1
- package/dist/core/storage/world-storage.js +5 -1
- package/dist/core/storage/world-storage.js.map +1 -1
- package/dist/core/storage-init.d.ts +11 -0
- package/dist/core/storage-init.d.ts.map +1 -0
- package/dist/core/storage-init.js +122 -0
- package/dist/core/storage-init.js.map +1 -0
- package/dist/core/subscription.d.ts +8 -1
- package/dist/core/subscription.d.ts.map +1 -1
- package/dist/core/subscription.js +130 -23
- package/dist/core/subscription.js.map +1 -1
- package/dist/core/tool-approval.d.ts +45 -0
- package/dist/core/tool-approval.d.ts.map +1 -0
- package/dist/core/tool-approval.js +223 -0
- package/dist/core/tool-approval.js.map +1 -0
- package/dist/core/tool-execution-envelope.d.ts +87 -0
- package/dist/core/tool-execution-envelope.d.ts.map +1 -0
- package/dist/core/tool-execution-envelope.js +168 -0
- package/dist/core/tool-execution-envelope.js.map +1 -0
- package/dist/core/tool-utils.d.ts +7 -2
- package/dist/core/tool-utils.d.ts.map +1 -1
- package/dist/core/tool-utils.js +81 -17
- package/dist/core/tool-utils.js.map +1 -1
- package/dist/core/types.d.ts +67 -19
- package/dist/core/types.d.ts.map +1 -1
- package/dist/core/types.js +3 -0
- package/dist/core/types.js.map +1 -1
- package/dist/core/utils.d.ts +7 -0
- package/dist/core/utils.d.ts.map +1 -1
- package/dist/core/utils.js +71 -21
- package/dist/core/utils.js.map +1 -1
- package/dist/core/web-fetch-tool.d.ts +72 -0
- package/dist/core/web-fetch-tool.d.ts.map +1 -0
- package/dist/core/web-fetch-tool.js +491 -0
- package/dist/core/web-fetch-tool.js.map +1 -0
- package/dist/core/world-registry.d.ts +84 -0
- package/dist/core/world-registry.d.ts.map +1 -0
- package/dist/core/world-registry.js +247 -0
- package/dist/core/world-registry.js.map +1 -0
- package/dist/public/assets/index-Be-1xtV-.js +104 -0
- package/dist/public/assets/index-tsDdiXDU.css +1 -0
- package/dist/public/index.html +2 -2
- package/dist/public/mcp-sandbox-proxy.html +148 -0
- package/dist/server/api.js +260 -18
- package/dist/server/error-response.d.ts +27 -0
- package/dist/server/error-response.js +77 -0
- package/dist/server/index.d.ts +2 -1
- package/dist/server/index.js +6 -2
- package/dist/server/sse-handler.d.ts +11 -1
- package/dist/server/sse-handler.js +194 -34
- package/migrations/0015_add_message_queue.sql +36 -0
- package/migrations/0016_add_world_heartbeat.sql +13 -0
- package/migrations/0017_add_title_provenance.sql +7 -0
- package/package.json +31 -10
- package/dist/public/assets/index-BW41BxMy.css +0 -1
- package/dist/public/assets/index-kO6UJFwK.js +0 -96
package/dist/core/hitl-tool.js
CHANGED
|
@@ -2,12 +2,11 @@
|
|
|
2
2
|
* HITL Request Tool Module - Built-in tool for generic human-in-the-loop input
|
|
3
3
|
*
|
|
4
4
|
* Purpose:
|
|
5
|
-
* - Expose a built-in `human_intervention_request` tool that lets the model ask questions
|
|
5
|
+
* - Expose a built-in `human_intervention_request` tool that lets the model ask questions and offer options.
|
|
6
6
|
*
|
|
7
7
|
* Key Features:
|
|
8
8
|
* - Supports option-only response mode for deterministic user selection.
|
|
9
9
|
* - Uses existing world-scoped HITL option runtime.
|
|
10
|
-
* - Supports explicit confirmation/cancel flow with deterministic timeout behavior.
|
|
11
10
|
* - Returns structured JSON payloads for stable downstream model parsing.
|
|
12
11
|
*
|
|
13
12
|
* Implementation Notes:
|
|
@@ -16,14 +15,15 @@
|
|
|
16
15
|
* - Tool execution requires world context; no external side effects beyond HITL events.
|
|
17
16
|
*
|
|
18
17
|
* Recent Changes:
|
|
18
|
+
* - 2026-03-06: Removed `world.currentChatId` fallback from HITL approval routing; interactive requests now require explicit `context.chatId`.
|
|
19
|
+
* - 2026-02-28: Added shorthand default-option resolution so values like "No" can map to a single matching option label.
|
|
20
|
+
* - 2026-02-27: Removed built-in post-selection confirmation stage and removed deprecated confirmation parameters from the tool contract.
|
|
19
21
|
* - 2026-02-20: Removed free-text mode from `human_intervention_request`; tool now enforces options-only interactions.
|
|
20
22
|
* - 2026-02-20: Added initial built-in `human_intervention_request` tool implementation.
|
|
21
23
|
*/
|
|
22
24
|
import { requestWorldOption } from './hitl.js';
|
|
23
25
|
const MODE_OPTION = 'option';
|
|
24
|
-
const
|
|
25
|
-
const CANCEL_OPTION_ID = 'cancel';
|
|
26
|
-
const DEFAULT_TIMEOUT_MESSAGE = 'HITL request timed out before user confirmation.';
|
|
26
|
+
const DEFAULT_TIMEOUT_MESSAGE = 'HITL request timed out before user selection.';
|
|
27
27
|
function stringifyResult(payload) {
|
|
28
28
|
return JSON.stringify(payload);
|
|
29
29
|
}
|
|
@@ -60,18 +60,42 @@ function normalizeTimeoutMs(value) {
|
|
|
60
60
|
}
|
|
61
61
|
return Math.floor(parsed);
|
|
62
62
|
}
|
|
63
|
+
function escapeRegExp(value) {
|
|
64
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
65
|
+
}
|
|
66
|
+
function resolveDefaultOptionLabel(options, defaultOption) {
|
|
67
|
+
const normalizedDefaultOption = defaultOption.trim().toLowerCase();
|
|
68
|
+
if (!normalizedDefaultOption) {
|
|
69
|
+
return { matchedOption: null, error: null };
|
|
70
|
+
}
|
|
71
|
+
const explicitMatch = options.find((option) => option.toLowerCase() === normalizedDefaultOption);
|
|
72
|
+
if (explicitMatch) {
|
|
73
|
+
return { matchedOption: explicitMatch, error: null };
|
|
74
|
+
}
|
|
75
|
+
const shorthandPattern = new RegExp(`^${escapeRegExp(normalizedDefaultOption)}(?:\\b|[\\s,;:()\\-])`, 'i');
|
|
76
|
+
const shorthandMatches = options.filter((option) => shorthandPattern.test(option));
|
|
77
|
+
if (shorthandMatches.length === 1) {
|
|
78
|
+
return { matchedOption: shorthandMatches[0], error: null };
|
|
79
|
+
}
|
|
80
|
+
if (shorthandMatches.length > 1) {
|
|
81
|
+
return {
|
|
82
|
+
matchedOption: null,
|
|
83
|
+
error: `defaultOption '${defaultOption}' is ambiguous across provided options.`,
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
return {
|
|
87
|
+
matchedOption: null,
|
|
88
|
+
error: `defaultOption '${defaultOption}' does not match any provided option.`,
|
|
89
|
+
};
|
|
90
|
+
}
|
|
63
91
|
function validateAndNormalizeArgs(args) {
|
|
64
92
|
const question = normalizeQuestion(args.question);
|
|
65
93
|
if (!question) {
|
|
66
94
|
return { valid: false, error: 'Missing required parameter: question' };
|
|
67
95
|
}
|
|
68
96
|
const options = normalizeOptionList(args.options);
|
|
69
|
-
const requireConfirmation = args.requireConfirmation === true;
|
|
70
|
-
const confirmationMessage = typeof args.confirmationMessage === 'string' && args.confirmationMessage.trim()
|
|
71
|
-
? args.confirmationMessage.trim()
|
|
72
|
-
: null;
|
|
73
97
|
const timeoutMs = normalizeTimeoutMs(args.timeoutMs);
|
|
74
|
-
const
|
|
98
|
+
const rawDefaultOption = typeof args.defaultOption === 'string' && args.defaultOption.trim()
|
|
75
99
|
? args.defaultOption.trim()
|
|
76
100
|
: null;
|
|
77
101
|
const metadata = args.metadata && typeof args.metadata === 'object'
|
|
@@ -83,24 +107,22 @@ function validateAndNormalizeArgs(args) {
|
|
|
83
107
|
error: 'HITL request requires at least one option.',
|
|
84
108
|
};
|
|
85
109
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
}
|
|
110
|
+
const resolvedDefaultOption = rawDefaultOption
|
|
111
|
+
? resolveDefaultOptionLabel(options, rawDefaultOption)
|
|
112
|
+
: { matchedOption: null, error: null };
|
|
113
|
+
if (resolvedDefaultOption.error) {
|
|
114
|
+
return {
|
|
115
|
+
valid: false,
|
|
116
|
+
error: resolvedDefaultOption.error,
|
|
117
|
+
};
|
|
94
118
|
}
|
|
95
119
|
return {
|
|
96
120
|
valid: true,
|
|
97
121
|
args: {
|
|
98
122
|
question,
|
|
99
123
|
options,
|
|
100
|
-
requireConfirmation,
|
|
101
|
-
confirmationMessage,
|
|
102
124
|
timeoutMs,
|
|
103
|
-
defaultOption,
|
|
125
|
+
defaultOption: resolvedDefaultOption.matchedOption,
|
|
104
126
|
metadata,
|
|
105
127
|
},
|
|
106
128
|
};
|
|
@@ -119,7 +141,7 @@ function buildOptionPromptOptions(optionLabels) {
|
|
|
119
141
|
}));
|
|
120
142
|
}
|
|
121
143
|
async function requestPrimaryResolution(options) {
|
|
122
|
-
const { world, chatId, args } = options;
|
|
144
|
+
const { world, chatId, args, agentName } = options;
|
|
123
145
|
const promptOptions = buildOptionPromptOptions(args.options);
|
|
124
146
|
const optionResolution = await requestWorldOption(world, {
|
|
125
147
|
title: 'Human input required',
|
|
@@ -132,7 +154,11 @@ async function requestPrimaryResolution(options) {
|
|
|
132
154
|
...(args.metadata || {}),
|
|
133
155
|
tool: 'human_intervention_request',
|
|
134
156
|
mode: MODE_OPTION,
|
|
157
|
+
...(typeof options.toolCallId === 'string' && options.toolCallId.trim()
|
|
158
|
+
? { toolCallId: options.toolCallId.trim() }
|
|
159
|
+
: {}),
|
|
135
160
|
},
|
|
161
|
+
agentName: agentName || null,
|
|
136
162
|
});
|
|
137
163
|
const selectedOption = promptOptions.find((option) => option.id === optionResolution.optionId)?.label || null;
|
|
138
164
|
return {
|
|
@@ -141,38 +167,6 @@ async function requestPrimaryResolution(options) {
|
|
|
141
167
|
source: optionResolution.source,
|
|
142
168
|
};
|
|
143
169
|
}
|
|
144
|
-
function buildConfirmationSummary(resolution) {
|
|
145
|
-
return `Selected option: ${resolution.selectedOption ?? ''}`;
|
|
146
|
-
}
|
|
147
|
-
async function requestConfirmation(options) {
|
|
148
|
-
const confirmation = await requestWorldOption(options.world, {
|
|
149
|
-
title: 'Confirm response',
|
|
150
|
-
message: [
|
|
151
|
-
options.question,
|
|
152
|
-
'',
|
|
153
|
-
buildConfirmationSummary(options.resolution),
|
|
154
|
-
'',
|
|
155
|
-
options.confirmationMessage || 'Please confirm to continue.',
|
|
156
|
-
].join('\n'),
|
|
157
|
-
chatId: options.chatId,
|
|
158
|
-
timeoutMs: options.timeoutMs ?? undefined,
|
|
159
|
-
defaultOptionId: CANCEL_OPTION_ID,
|
|
160
|
-
options: [
|
|
161
|
-
{ id: CONFIRM_OPTION_ID, label: 'Confirm', description: 'Use this response and continue.' },
|
|
162
|
-
{ id: CANCEL_OPTION_ID, label: 'Cancel', description: 'Cancel this HITL request.' },
|
|
163
|
-
],
|
|
164
|
-
metadata: {
|
|
165
|
-
...(options.metadata || {}),
|
|
166
|
-
tool: 'human_intervention_request',
|
|
167
|
-
mode: 'confirmation',
|
|
168
|
-
requestId: options.resolution.requestId,
|
|
169
|
-
},
|
|
170
|
-
});
|
|
171
|
-
if (confirmation.optionId === CONFIRM_OPTION_ID) {
|
|
172
|
-
return { confirmed: true, source: confirmation.source };
|
|
173
|
-
}
|
|
174
|
-
return { confirmed: false, source: confirmation.source };
|
|
175
|
-
}
|
|
176
170
|
function buildFinalResult(options) {
|
|
177
171
|
const ok = options.status === 'confirmed';
|
|
178
172
|
return stringifyResult({
|
|
@@ -187,7 +181,7 @@ function buildFinalResult(options) {
|
|
|
187
181
|
}
|
|
188
182
|
export function createHitlToolDefinition() {
|
|
189
183
|
return {
|
|
190
|
-
description: 'Ask a human a question
|
|
184
|
+
description: 'Ask a human a question and offer choices; returns after a single option selection.',
|
|
191
185
|
parameters: {
|
|
192
186
|
type: 'object',
|
|
193
187
|
properties: {
|
|
@@ -200,14 +194,6 @@ export function createHitlToolDefinition() {
|
|
|
200
194
|
items: { type: 'string' },
|
|
201
195
|
description: 'Required list of selectable options.',
|
|
202
196
|
},
|
|
203
|
-
requireConfirmation: {
|
|
204
|
-
type: 'boolean',
|
|
205
|
-
description: 'When true, human must explicitly confirm before completion.',
|
|
206
|
-
},
|
|
207
|
-
confirmationMessage: {
|
|
208
|
-
type: 'string',
|
|
209
|
-
description: 'Optional extra text shown in confirmation prompt.',
|
|
210
|
-
},
|
|
211
197
|
timeoutMs: {
|
|
212
198
|
type: 'number',
|
|
213
199
|
description: 'Optional timeout for HITL prompts in milliseconds.',
|
|
@@ -247,36 +233,28 @@ export function createHitlToolDefinition() {
|
|
|
247
233
|
message: 'human_intervention_request requires a valid world context.',
|
|
248
234
|
});
|
|
249
235
|
}
|
|
250
|
-
const chatId = context?.chatId
|
|
236
|
+
const chatId = typeof context?.chatId === 'string' && context.chatId.trim()
|
|
237
|
+
? context.chatId.trim()
|
|
238
|
+
: null;
|
|
239
|
+
const agentName = context?.agentName || null;
|
|
240
|
+
if (!chatId) {
|
|
241
|
+
return buildFinalResult({
|
|
242
|
+
requestId: '',
|
|
243
|
+
selectedOption: null,
|
|
244
|
+
status: 'error',
|
|
245
|
+
source: 'system',
|
|
246
|
+
message: 'human_intervention_request requires an explicit chatId in the tool execution context.',
|
|
247
|
+
});
|
|
248
|
+
}
|
|
251
249
|
try {
|
|
252
250
|
const primaryResolution = await requestPrimaryResolution({
|
|
253
251
|
world,
|
|
254
252
|
chatId,
|
|
255
253
|
args: normalized.args,
|
|
254
|
+
agentName,
|
|
255
|
+
toolCallId: context.toolCallId,
|
|
256
256
|
});
|
|
257
|
-
if (
|
|
258
|
-
const confirmation = await requestConfirmation({
|
|
259
|
-
world,
|
|
260
|
-
chatId,
|
|
261
|
-
question: normalized.args.question,
|
|
262
|
-
resolution: primaryResolution,
|
|
263
|
-
timeoutMs: normalized.args.timeoutMs,
|
|
264
|
-
confirmationMessage: normalized.args.confirmationMessage,
|
|
265
|
-
metadata: normalized.args.metadata,
|
|
266
|
-
});
|
|
267
|
-
if (!confirmation.confirmed) {
|
|
268
|
-
return buildFinalResult({
|
|
269
|
-
requestId: primaryResolution.requestId,
|
|
270
|
-
selectedOption: primaryResolution.selectedOption,
|
|
271
|
-
status: confirmation.source === 'timeout' ? 'timeout' : 'canceled',
|
|
272
|
-
source: confirmation.source,
|
|
273
|
-
message: confirmation.source === 'timeout'
|
|
274
|
-
? DEFAULT_TIMEOUT_MESSAGE
|
|
275
|
-
: 'HITL request was canceled.',
|
|
276
|
-
});
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
else if (primaryResolution.source === 'timeout') {
|
|
257
|
+
if (primaryResolution.source === 'timeout') {
|
|
280
258
|
return buildFinalResult({
|
|
281
259
|
requestId: primaryResolution.requestId,
|
|
282
260
|
selectedOption: primaryResolution.selectedOption,
|
|
@@ -289,7 +267,7 @@ export function createHitlToolDefinition() {
|
|
|
289
267
|
requestId: primaryResolution.requestId,
|
|
290
268
|
selectedOption: primaryResolution.selectedOption,
|
|
291
269
|
status: 'confirmed',
|
|
292
|
-
source:
|
|
270
|
+
source: primaryResolution.source,
|
|
293
271
|
});
|
|
294
272
|
}
|
|
295
273
|
catch (error) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hitl-tool.js","sourceRoot":"","sources":["../../core/hitl-tool.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"hitl-tool.js","sourceRoot":"","sources":["../../core/hitl-tool.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,EAAE,kBAAkB,EAAmB,MAAM,WAAW,CAAC;AAGhE,MAAM,WAAW,GAAG,QAAQ,CAAC;AAC7B,MAAM,uBAAuB,GAAG,+CAA+C,CAAC;AA+BhF,SAAS,eAAe,CAAC,OAAgC;IACvD,OAAO,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;AACjC,CAAC;AAED,SAAS,iBAAiB,CAAC,QAAiB;IAC1C,OAAO,MAAM,CAAC,QAAQ,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;AACvC,CAAC;AAED,SAAS,mBAAmB,CAAC,OAAgB;IAC3C,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,E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|
5
5
|
* - Provide a world-scoped request/response flow for option-based HITL prompts.
|
|
6
6
|
*
|
|
7
7
|
* Key Features:
|
|
8
|
-
* - Emits structured
|
|
8
|
+
* - Emits structured tool-progress events carrying HITL prompt payloads.
|
|
9
9
|
* - Resolves pending requests when renderer/API submits an option response.
|
|
10
|
-
* -
|
|
10
|
+
* - Exposes unresolved option prompts through a deterministic read model.
|
|
11
11
|
* - Maintains pending request map for validation and lifecycle cleanup.
|
|
12
12
|
*
|
|
13
13
|
* Implementation Notes:
|
|
14
14
|
* - Requests are keyed by `(worldId, requestId)` to avoid cross-world collisions.
|
|
15
|
-
* -
|
|
15
|
+
* - Prompt read model is deterministic and scoped by `(worldId, chatId)`.
|
|
16
16
|
* - Runtime is in-memory and process-local by design.
|
|
17
17
|
*
|
|
18
18
|
* Recent Changes:
|
|
19
|
+
* - 2026-03-12: Relaxed the hard `requestId === toolCallId` invariant so durable approval prompts can keep distinct request and owning-tool identities.
|
|
20
|
+
* - 2026-03-06: Removed `world.currentChatId` fallback from HITL option requests; interactive requests now require explicit `chatId`.
|
|
21
|
+
* - 2026-02-26: Replaced direct `[hitl]` console traces with categorized structured logger events (`hitl`) for env-controlled filtering.
|
|
22
|
+
* - 2026-02-25: Added HITL runtime trace logs for request emission, replay, and resolution lifecycle diagnostics.
|
|
23
|
+
* - 2026-02-24: Removed HITL `system` event emission/replay and switched to tool-progress prompt payloads.
|
|
24
|
+
* - 2026-02-24: Added `listPendingHitlPromptEvents` to expose scoped pending HITL prompt payloads for web chat-switch replay.
|
|
25
|
+
* - 2026-02-24: Removed timeout auto-resolution and added deterministic replay helpers for unresolved HITL requests.
|
|
19
26
|
* - 2026-02-20: Enforced global options-only HITL runtime by removing input-mode request/response paths.
|
|
20
27
|
* - 2026-02-14: Added initial generic HITL option request/response runtime.
|
|
21
28
|
*/
|
|
22
|
-
import { type World } from './types.js';
|
|
29
|
+
import { type AgentMessage, type World } from './types.js';
|
|
23
30
|
export interface HitlOption {
|
|
24
31
|
id: string;
|
|
25
32
|
label: string;
|
|
@@ -34,6 +41,7 @@ export interface HitlOptionRequest {
|
|
|
34
41
|
timeoutMs?: number;
|
|
35
42
|
defaultOptionId?: string;
|
|
36
43
|
metadata?: Record<string, unknown>;
|
|
44
|
+
agentName?: string | null;
|
|
37
45
|
}
|
|
38
46
|
export interface HitlOptionResolution {
|
|
39
47
|
requestId: string;
|
|
@@ -49,7 +57,55 @@ export type HitlResponseResolution = {
|
|
|
49
57
|
optionId: string;
|
|
50
58
|
source: 'user' | 'timeout';
|
|
51
59
|
};
|
|
60
|
+
interface PendingHitlOptionRequest {
|
|
61
|
+
worldId: string;
|
|
62
|
+
requestId: string;
|
|
63
|
+
chatId: string | null;
|
|
64
|
+
optionIds: Set<string>;
|
|
65
|
+
sequence: number;
|
|
66
|
+
prompt: {
|
|
67
|
+
requestId: string;
|
|
68
|
+
title: string;
|
|
69
|
+
message: string;
|
|
70
|
+
options: HitlOption[];
|
|
71
|
+
defaultOptionId: string;
|
|
72
|
+
metadata: Record<string, unknown> | null;
|
|
73
|
+
agentName: string | null;
|
|
74
|
+
toolName: string;
|
|
75
|
+
toolCallId: string;
|
|
76
|
+
};
|
|
77
|
+
metadata: Record<string, unknown> | null;
|
|
78
|
+
resolve: (resolution: HitlResponseResolution) => void;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Remove all pending HITL requests scoped to a specific chat.
|
|
82
|
+
* Called during edit+resubmit so orphaned requests from aborted processing
|
|
83
|
+
* do not block the activity tracker or leak into subscription replays.
|
|
84
|
+
*/
|
|
85
|
+
export declare function clearPendingHitlRequestsForChat(worldId: string, chatId: string | null): void;
|
|
52
86
|
export declare function requestWorldOption(world: World, request: HitlOptionRequest): Promise<HitlOptionResolution>;
|
|
87
|
+
export declare function listPendingHitlPromptEventsFromMessages(messages: AgentMessage[], chatId?: string | null): Array<{
|
|
88
|
+
chatId: string | null;
|
|
89
|
+
prompt: {
|
|
90
|
+
requestId: string;
|
|
91
|
+
title: string;
|
|
92
|
+
message: string;
|
|
93
|
+
options: Array<{
|
|
94
|
+
id: string;
|
|
95
|
+
label: string;
|
|
96
|
+
}>;
|
|
97
|
+
defaultOptionId: string;
|
|
98
|
+
metadata: Record<string, unknown> | null;
|
|
99
|
+
agentName: string | null;
|
|
100
|
+
toolName: string;
|
|
101
|
+
toolCallId: string;
|
|
102
|
+
};
|
|
103
|
+
}>;
|
|
104
|
+
export declare function replayPendingHitlRequests(world: World, chatId?: string | null): number;
|
|
105
|
+
export declare function listPendingHitlPromptEvents(world: World, chatId?: string | null): Array<{
|
|
106
|
+
chatId: string | null;
|
|
107
|
+
prompt: PendingHitlOptionRequest['prompt'];
|
|
108
|
+
}>;
|
|
53
109
|
export declare function submitWorldOptionResponse(params: {
|
|
54
110
|
worldId: string;
|
|
55
111
|
requestId: string;
|
|
@@ -71,3 +127,4 @@ export declare function submitWorldHitlResponse(params: {
|
|
|
71
127
|
metadata?: Record<string, unknown> | null;
|
|
72
128
|
};
|
|
73
129
|
export declare function clearHitlStateForTests(): void;
|
|
130
|
+
export {};
|
package/dist/core/hitl.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hitl.d.ts","sourceRoot":"","sources":["../../core/hitl.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"hitl.d.ts","sourceRoot":"","sources":["../../core/hitl.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,OAAO,EAAE,KAAK,YAAY,EAAE,KAAK,KAAK,EAAE,MAAM,YAAY,CAAC;AAI3D,MAAM,WAAW,UAAU;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,iBAAiB;IAChC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,C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