@mupt-ai/dari-gateway 0.0.0-stage → 0.2.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 (133) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +135 -2
  3. package/dari-gateway.example.yaml +28 -0
  4. package/package.json +42 -4
  5. package/src/bun.ts +4 -0
  6. package/src/context/eval_catalog.ts +11 -0
  7. package/src/context/interaction_fingerprint.ts +691 -0
  8. package/src/context/interaction_fingerprint_format.ts +189 -0
  9. package/src/context/interaction_lease_depth.ts +150 -0
  10. package/src/context/lease_history.ts +200 -0
  11. package/src/context/pricing.ts +30 -0
  12. package/src/context/provider_prompt_accounting.ts +241 -0
  13. package/src/context/routing_context.ts +337 -0
  14. package/src/http/auth.ts +43 -0
  15. package/src/http/errors.ts +114 -0
  16. package/src/http/handler.ts +110 -0
  17. package/src/http/http2_server.ts +122 -0
  18. package/src/http/serve.ts +119 -0
  19. package/src/index.ts +22 -0
  20. package/src/ingress/anthropic_messages.ts +162 -0
  21. package/src/ingress/anthropic_models.ts +28 -0
  22. package/src/ingress/chat_completions.ts +49 -0
  23. package/src/ingress/claude_code/request_context.ts +36 -0
  24. package/src/ingress/codex.ts +81 -0
  25. package/src/ingress/codex_models.ts +113 -0
  26. package/src/ingress/json.ts +113 -0
  27. package/src/ingress/models.ts +55 -0
  28. package/src/interaction/capabilities.ts +30 -0
  29. package/src/interaction/image.ts +12 -0
  30. package/src/interaction/portable_reasoning_state.ts +25 -0
  31. package/src/interaction/provider_continuation_state.ts +36 -0
  32. package/src/interaction/tool_identity.ts +65 -0
  33. package/src/interaction/types.ts +282 -0
  34. package/src/models/context_limits.ts +8 -0
  35. package/src/models/execution_provider.ts +22 -0
  36. package/src/models/gateways.ts +73 -0
  37. package/src/models/ids.ts +26 -0
  38. package/src/models/provider_defaults.ts +47 -0
  39. package/src/models/runtime_overrides.ts +221 -0
  40. package/src/observability/errors.ts +25 -0
  41. package/src/platform/platform.ts +204 -0
  42. package/src/platform/routing_contract.ts +6 -0
  43. package/src/protocol/input/anthropic_messages.ts +531 -0
  44. package/src/protocol/input/chat_completions.ts +255 -0
  45. package/src/protocol/input/chat_completions_validation.ts +293 -0
  46. package/src/protocol/input/openai_responses.ts +749 -0
  47. package/src/protocol/input/router_model.ts +53 -0
  48. package/src/protocol/output/anthropic_messages.ts +32 -0
  49. package/src/protocol/output/anthropic_messages_output.ts +129 -0
  50. package/src/protocol/output/anthropic_messages_stream.ts +281 -0
  51. package/src/protocol/output/chat_completions.ts +451 -0
  52. package/src/protocol/output/chat_reasoning_detail.ts +19 -0
  53. package/src/protocol/output/delivered_stream_snapshot.ts +31 -0
  54. package/src/protocol/output/openai_responses.ts +30 -0
  55. package/src/protocol/output/openai_responses_output.ts +159 -0
  56. package/src/protocol/output/openai_responses_stream.ts +631 -0
  57. package/src/protocol/output/sse_stream.ts +102 -0
  58. package/src/providers/anthropic_safeguards.ts +115 -0
  59. package/src/providers/aws_assume_role.ts +147 -0
  60. package/src/providers/cancel_estimate.ts +140 -0
  61. package/src/providers/execution.ts +800 -0
  62. package/src/providers/model_capabilities.ts +50 -0
  63. package/src/providers/pi.ts +499 -0
  64. package/src/providers/pi_context.ts +466 -0
  65. package/src/providers/pi_options.ts +416 -0
  66. package/src/providers/pi_output.ts +500 -0
  67. package/src/providers/provider_attempt_runner.ts +153 -0
  68. package/src/providers/provider_call.ts +433 -0
  69. package/src/providers/provider_reported_cost.ts +138 -0
  70. package/src/providers/reasoning.ts +59 -0
  71. package/src/providers/response_capture.ts +65 -0
  72. package/src/providers/stream_finalization.ts +264 -0
  73. package/src/providers/subscription_limits.ts +208 -0
  74. package/src/providers/subscription_usage.ts +99 -0
  75. package/src/runtime/claude_code/auxiliary_routing.ts +80 -0
  76. package/src/runtime/customer_disconnect.ts +66 -0
  77. package/src/runtime/explicit_model.ts +86 -0
  78. package/src/runtime/harness_identity/conversation.ts +87 -0
  79. package/src/runtime/harness_identity/extract.ts +323 -0
  80. package/src/runtime/harness_identity/index.ts +14 -0
  81. package/src/runtime/prepare_routed_completion.ts +224 -0
  82. package/src/runtime/provider_stream_lifecycle.ts +105 -0
  83. package/src/runtime/provider_stream_outcome.ts +83 -0
  84. package/src/runtime/request_tags.ts +34 -0
  85. package/src/runtime/routed_completion.ts +102 -0
  86. package/src/runtime/routed_protocol.ts +33 -0
  87. package/src/runtime/routed_runtime.ts +722 -0
  88. package/src/runtime/routing_lease.ts +273 -0
  89. package/src/runtime/runtime_reporter.ts +115 -0
  90. package/src/self_host/config.ts +173 -0
  91. package/src/self_host/main.ts +104 -0
  92. package/src/self_host/platform.ts +63 -0
  93. package/src/self_host/prefix_store.ts +315 -0
  94. package/src/self_host/resolve.ts +240 -0
  95. package/src/self_host/subscriptions/access.ts +43 -0
  96. package/src/self_host/subscriptions/http.ts +204 -0
  97. package/src/self_host/subscriptions/index.ts +43 -0
  98. package/src/self_host/subscriptions/oauth.ts +395 -0
  99. package/src/self_host/subscriptions/store.ts +339 -0
  100. package/src/strategies/auto_routing_selector.ts +72 -0
  101. package/src/strategies/eval_relevance.ts +57 -0
  102. package/src/strategies/fallback_decision.ts +30 -0
  103. package/src/strategies/priority_selector.ts +40 -0
  104. package/src/strategies/route_decision.ts +106 -0
  105. package/src/strategies/routing.ts +455 -0
  106. package/src/strategies/selector_projection.ts +207 -0
  107. package/src/telemetry/background.ts +40 -0
  108. package/src/telemetry/benchmark_replay.ts +160 -0
  109. package/src/telemetry/billing_finalization.ts +167 -0
  110. package/src/telemetry/ingest_values.ts +15 -0
  111. package/src/telemetry/model_cost.ts +14 -0
  112. package/src/telemetry/prefix_state.ts +183 -0
  113. package/src/telemetry/report.ts +832 -0
  114. package/src/telemetry/requests/interaction_observability.ts +258 -0
  115. package/src/telemetry/requests/retained_interaction_request.ts +20 -0
  116. package/src/telemetry/scrub.ts +38 -0
  117. package/src/telemetry/skills/claude/catalog.ts +119 -0
  118. package/src/telemetry/skills/claude/file_reads.ts +153 -0
  119. package/src/telemetry/skills/claude/observations.ts +450 -0
  120. package/src/telemetry/skills/codex/catalog.ts +171 -0
  121. package/src/telemetry/skills/codex/exec_file_reads.ts +55 -0
  122. package/src/telemetry/skills/codex/explicit.ts +116 -0
  123. package/src/telemetry/skills/codex/file_reads.ts +51 -0
  124. package/src/telemetry/skills/codex/identity.ts +21 -0
  125. package/src/telemetry/skills/observations.ts +94 -0
  126. package/src/telemetry/skills/paths.ts +82 -0
  127. package/src/telemetry/skills/pi.ts +276 -0
  128. package/src/telemetry/skills/shell_file_reads.ts +267 -0
  129. package/src/telemetry/skills/shell_words.ts +202 -0
  130. package/src/telemetry/tools/input.ts +16 -0
  131. package/src/telemetry/tools/observations.ts +349 -0
  132. package/src/telemetry/usage.ts +173 -0
  133. package/src/types.ts +150 -0
@@ -0,0 +1,267 @@
1
+ import {
2
+ normalizedAbsoluteSkillPath,
3
+ resolvedSkillPath,
4
+ type NormalizedSkillPath,
5
+ type PathPlatform,
6
+ } from "./paths";
7
+ import {
8
+ executableCommand,
9
+ restrictedShellSegments,
10
+ trustedExecutableName,
11
+ type ShellOperator,
12
+ } from "./shell_words";
13
+
14
+ const MAX_SHELL_NESTING = 16;
15
+ const NO_VALUE_FLAGS = new Set<string>();
16
+ const BAT_VALUE_FLAGS = new Set([
17
+ "--language",
18
+ "--line-range",
19
+ "--map-syntax",
20
+ "--style",
21
+ "--tabs",
22
+ "--terminal-width",
23
+ "--theme",
24
+ ]);
25
+ const HEAD_TAIL_VALUE_FLAGS = new Set(["-c", "--bytes", "-n", "--lines"]);
26
+ const LESS_VALUE_FLAGS = new Set([
27
+ "--LOG-FILE",
28
+ "-j",
29
+ "--jump-target",
30
+ "--log-file",
31
+ "-o",
32
+ "-O",
33
+ "-p",
34
+ "--pattern",
35
+ "-P",
36
+ "--prompt",
37
+ "--shift",
38
+ "--tabs",
39
+ "-x",
40
+ "-y",
41
+ "-z",
42
+ ]);
43
+ const NL_VALUE_FLAGS = new Set([
44
+ "--body-numbering",
45
+ "--footer-numbering",
46
+ "--header-numbering",
47
+ "--join-blank-lines",
48
+ "--number-format",
49
+ "--number-separator",
50
+ "--number-width",
51
+ "--section-delimiter",
52
+ "--starting-line-number",
53
+ "-b",
54
+ "-d",
55
+ "-f",
56
+ "-h",
57
+ "-i",
58
+ "-n",
59
+ "-s",
60
+ "-v",
61
+ "-w",
62
+ ]);
63
+ const AWK_VALUE_FLAGS = new Set(["-F", "-v"]);
64
+
65
+ export type ShellReadCommand = {
66
+ command: string;
67
+ workdir?: string;
68
+ };
69
+
70
+ /** Parse only direct, deterministic shell readers and return their resolved paths. */
71
+ export function readPathsFromShellCommand(
72
+ input: ShellReadCommand,
73
+ platform: PathPlatform,
74
+ nesting = 0,
75
+ ): NormalizedSkillPath[] {
76
+ if (nesting > MAX_SHELL_NESTING) return [];
77
+ const segments = restrictedShellSegments(input.command, platform);
78
+ if (segments === undefined) return [];
79
+ const normalizedWorkdir = normalizedAbsoluteSkillPath(input.workdir);
80
+ let workdir = normalizedWorkdir?.platform === platform
81
+ ? normalizedWorkdir
82
+ : undefined;
83
+ const observed: NormalizedSkillPath[] = [];
84
+ let previousOperator: ShellOperator | null = null;
85
+ let previousWasSupported = false;
86
+
87
+ for (const segment of segments) {
88
+ const command = executableCommand(segment.words);
89
+ if (command === undefined) {
90
+ previousOperator = segment.next;
91
+ previousWasSupported = false;
92
+ continue;
93
+ }
94
+ const executable = trustedExecutableName(command.executable, platform);
95
+ if (executable === undefined) {
96
+ previousOperator = segment.next;
97
+ previousWasSupported = false;
98
+ continue;
99
+ }
100
+ if (previousOperator === "||") return [];
101
+ if (previousOperator === "&&" && !previousWasSupported) {
102
+ previousOperator = segment.next;
103
+ previousWasSupported = false;
104
+ continue;
105
+ }
106
+ if (executable === "cd") {
107
+ const nextWorkdir = cdTarget(command.args, workdir, platform);
108
+ if (
109
+ nextWorkdir !== undefined
110
+ && (segment.next === "&&" || segment.next === ";" || segment.next === "\n")
111
+ ) workdir = nextWorkdir;
112
+ previousOperator = segment.next;
113
+ previousWasSupported = nextWorkdir !== undefined;
114
+ continue;
115
+ }
116
+ if (
117
+ platform === "posix"
118
+ && (executable === "bash" || executable === "zsh" || executable === "sh")
119
+ && command.args.length >= 2
120
+ && /^-[^-]*c[^-]*$/u.test(command.args[0])
121
+ ) {
122
+ observed.push(...readPathsFromShellCommand(
123
+ {
124
+ command: command.args[1],
125
+ ...(workdir === undefined ? {} : { workdir: workdir.value }),
126
+ },
127
+ platform,
128
+ nesting + 1,
129
+ ));
130
+ previousOperator = segment.next;
131
+ previousWasSupported = false;
132
+ continue;
133
+ }
134
+ const paths = readerPaths(executable, command.args, platform);
135
+ if (paths === undefined) {
136
+ previousOperator = segment.next;
137
+ previousWasSupported = false;
138
+ continue;
139
+ }
140
+ for (const path of paths) {
141
+ const resolved = resolvedSkillPath(path, workdir);
142
+ if (resolved?.platform === platform) observed.push(resolved);
143
+ }
144
+ previousOperator = segment.next;
145
+ previousWasSupported = true;
146
+ }
147
+ return observed;
148
+ }
149
+
150
+ function readerPaths(
151
+ executable: string,
152
+ args: string[],
153
+ platform: PathPlatform,
154
+ ): string[] | undefined {
155
+ switch (executable) {
156
+ case "cat":
157
+ case "more":
158
+ return ordinaryFileOperands(args, NO_VALUE_FLAGS);
159
+ case "bat":
160
+ case "batcat":
161
+ return ordinaryFileOperands(args, BAT_VALUE_FLAGS);
162
+ case "head":
163
+ case "tail":
164
+ return ordinaryFileOperands(args, HEAD_TAIL_VALUE_FLAGS);
165
+ case "less":
166
+ return ordinaryFileOperands(args, LESS_VALUE_FLAGS);
167
+ case "nl":
168
+ return ordinaryFileOperands(args, NL_VALUE_FLAGS);
169
+ case "sed":
170
+ return sedFileOperands(args);
171
+ case "awk":
172
+ return ordinaryFileOperands(args, AWK_VALUE_FLAGS).slice(1);
173
+ case "get-content":
174
+ case "gc":
175
+ case "type":
176
+ return platform === "windows" ? powershellFileOperands(args) : [];
177
+ default:
178
+ return undefined;
179
+ }
180
+ }
181
+
182
+ function ordinaryFileOperands(
183
+ args: string[],
184
+ valueFlags: ReadonlySet<string>,
185
+ ): string[] {
186
+ const files: string[] = [];
187
+ let optionsEnded = false;
188
+ for (let index = 0; index < args.length; index += 1) {
189
+ const argument = args[index];
190
+ if (!optionsEnded && argument === "--") {
191
+ optionsEnded = true;
192
+ continue;
193
+ }
194
+ if (!optionsEnded && valueFlags.has(argument)) {
195
+ index += 1;
196
+ continue;
197
+ }
198
+ if (!optionsEnded && argument.startsWith("-")) continue;
199
+ files.push(argument);
200
+ }
201
+ return files;
202
+ }
203
+
204
+ function sedFileOperands(args: string[]): string[] {
205
+ const files: string[] = [];
206
+ let explicitProgram = false;
207
+ let implicitProgramConsumed = false;
208
+ let optionsEnded = false;
209
+ for (let index = 0; index < args.length; index += 1) {
210
+ const argument = args[index];
211
+ if (!optionsEnded && argument === "--") {
212
+ optionsEnded = true;
213
+ continue;
214
+ }
215
+ if (!optionsEnded && ["-e", "--expression", "-f", "--file"].includes(argument)) {
216
+ explicitProgram = true;
217
+ index += 1;
218
+ continue;
219
+ }
220
+ if (!optionsEnded && (
221
+ argument.startsWith("-e")
222
+ || argument.startsWith("--expression=")
223
+ || argument.startsWith("-f")
224
+ || argument.startsWith("--file=")
225
+ )) {
226
+ explicitProgram = true;
227
+ continue;
228
+ }
229
+ if (!optionsEnded && argument.startsWith("-")) continue;
230
+ if (!explicitProgram && !implicitProgramConsumed) {
231
+ implicitProgramConsumed = true;
232
+ continue;
233
+ }
234
+ files.push(argument);
235
+ }
236
+ return files;
237
+ }
238
+
239
+ function powershellFileOperands(args: string[]): string[] {
240
+ const files: string[] = [];
241
+ for (let index = 0; index < args.length; index += 1) {
242
+ const argument = args[index];
243
+ if (/^-(?:Path|LiteralPath)$/iu.test(argument)) {
244
+ const path = args[index + 1];
245
+ if (path !== undefined) files.push(path);
246
+ index += 1;
247
+ continue;
248
+ }
249
+ if (!argument.startsWith("-")) files.push(argument);
250
+ }
251
+ return files;
252
+ }
253
+
254
+ function cdTarget(
255
+ args: string[],
256
+ workdir: NormalizedSkillPath | undefined,
257
+ platform: PathPlatform,
258
+ ): NormalizedSkillPath | undefined {
259
+ const operands = args.filter(
260
+ (argument) => argument !== "--" && !argument.startsWith("-"),
261
+ );
262
+ const target = operands.at(-1);
263
+ const resolved = target === undefined
264
+ ? undefined
265
+ : resolvedSkillPath(target, workdir);
266
+ return resolved?.platform === platform ? resolved : undefined;
267
+ }
@@ -0,0 +1,202 @@
1
+ import { posix, win32 } from "node:path";
2
+
3
+ import type { PathPlatform } from "./paths";
4
+
5
+ const MAX_COMMAND_TOKENS = 4_096;
6
+ const SHELL_ASSIGNMENT = /^[A-Za-z_][A-Za-z0-9_]*=/u;
7
+ const POSIX_SHELL_WHITESPACE = /[\t\n\v\f\r ]/u;
8
+ const POSIX_CONTROL_COMMANDS = new Set([
9
+ "!",
10
+ "[[",
11
+ "case",
12
+ "do",
13
+ "done",
14
+ "elif",
15
+ "else",
16
+ "esac",
17
+ "fi",
18
+ "for",
19
+ "function",
20
+ "if",
21
+ "select",
22
+ "then",
23
+ "time",
24
+ "until",
25
+ "while",
26
+ "{",
27
+ "}",
28
+ ]);
29
+ const TRUSTED_POSIX_EXECUTABLE_DIRECTORIES = new Set([
30
+ "/bin",
31
+ "/opt/homebrew/bin",
32
+ "/usr/bin",
33
+ "/usr/local/bin",
34
+ ]);
35
+
36
+ export type ShellOperator = "&" | "&&" | "|" | "||" | ";" | "\n";
37
+
38
+ export type ShellSegment = {
39
+ words: string[];
40
+ next: ShellOperator | null;
41
+ };
42
+
43
+ export type ExecutableCommand = {
44
+ executable: string;
45
+ args: string[];
46
+ };
47
+
48
+ export function executableCommand(
49
+ words: string[],
50
+ ): ExecutableCommand | undefined {
51
+ let index = 0;
52
+ while (index < words.length && SHELL_ASSIGNMENT.test(words[index])) index += 1;
53
+ if (words[index] === "env") {
54
+ index += 1;
55
+ while (
56
+ index < words.length
57
+ && (words[index].startsWith("-") || SHELL_ASSIGNMENT.test(words[index]))
58
+ ) index += 1;
59
+ }
60
+ if (words[index] === "command" || words[index] === "builtin") {
61
+ index += 1;
62
+ while (index < words.length && words[index].startsWith("-")) index += 1;
63
+ }
64
+ const executable = words[index];
65
+ return executable === undefined
66
+ ? undefined
67
+ : { executable, args: words.slice(index + 1) };
68
+ }
69
+
70
+ // This lexer recognizes only the shell structure needed to identify direct
71
+ // read commands. Unsupported substitutions and control flow fail closed.
72
+ export function restrictedShellSegments(
73
+ command: string,
74
+ platform: PathPlatform,
75
+ ): ShellSegment[] | undefined {
76
+ const powershell = platform === "windows";
77
+ if ((!powershell && (command.includes("$(") || command.includes("`"))) || command.includes("\u0000")) {
78
+ return undefined;
79
+ }
80
+ const segments: ShellSegment[] = [];
81
+ let words: string[] = [];
82
+ let word = "";
83
+ let wordStarted = false;
84
+ let quote: "'" | '"' | null = null;
85
+ let tokenCount = 0;
86
+
87
+ const flushWord = () => {
88
+ if (!wordStarted) return;
89
+ words.push(word);
90
+ tokenCount += 1;
91
+ word = "";
92
+ wordStarted = false;
93
+ };
94
+ const flushSegment = (next: ShellOperator) => {
95
+ flushWord();
96
+ if (words.length > 0) segments.push({ words, next });
97
+ words = [];
98
+ };
99
+
100
+ for (let index = 0; index < command.length; index += 1) {
101
+ const character = command[index];
102
+ if (quote !== null) {
103
+ if (character === quote) {
104
+ quote = null;
105
+ } else if (powershell && character === "`") {
106
+ index += 1;
107
+ if (index >= command.length) return undefined;
108
+ word += command[index];
109
+ } else if (!powershell && character === "\\" && quote === '"') {
110
+ const escaped = command[index + 1];
111
+ if (escaped === undefined) return undefined;
112
+ if (["$", "`", '"', "\\", "\n"].includes(escaped)) {
113
+ index += 1;
114
+ if (escaped !== "\n") word += escaped;
115
+ } else {
116
+ word += character;
117
+ }
118
+ } else {
119
+ word += character;
120
+ }
121
+ wordStarted = true;
122
+ continue;
123
+ }
124
+ if (character === "'" || character === '"') {
125
+ quote = character;
126
+ wordStarted = true;
127
+ continue;
128
+ }
129
+ if ((!powershell && character === "\\") || (powershell && character === "`")) {
130
+ index += 1;
131
+ if (index >= command.length) return undefined;
132
+ if (command[index] !== "\n") {
133
+ word += command[index];
134
+ wordStarted = true;
135
+ }
136
+ continue;
137
+ }
138
+ if (POSIX_SHELL_WHITESPACE.test(character)) {
139
+ flushWord();
140
+ if (character === "\n") flushSegment("\n");
141
+ continue;
142
+ }
143
+ if (character === "#" && !wordStarted) {
144
+ flushWord();
145
+ while (index + 1 < command.length && command[index + 1] !== "\n") index += 1;
146
+ continue;
147
+ }
148
+ if (character === ";" || character === "|" || character === "&") {
149
+ const doubled = command[index + 1] === character;
150
+ const operator = (doubled ? character + character : character) as ShellOperator;
151
+ if ((character === "|" || character === "&") && doubled) index += 1;
152
+ flushSegment(operator);
153
+ continue;
154
+ }
155
+ if (
156
+ character === "("
157
+ || character === ")"
158
+ || character === "<"
159
+ || character === ">"
160
+ ) return undefined;
161
+ word += character;
162
+ wordStarted = true;
163
+ }
164
+ if (quote !== null) return undefined;
165
+ flushWord();
166
+ if (words.length > 0) segments.push({ words, next: null });
167
+ if (
168
+ tokenCount > MAX_COMMAND_TOKENS
169
+ || segments.length > MAX_COMMAND_TOKENS
170
+ || (platform === "posix" && segments.some((segment) => {
171
+ const parsed = executableCommand(segment.words);
172
+ return parsed !== undefined
173
+ && POSIX_CONTROL_COMMANDS.has(parsed.executable);
174
+ }))
175
+ ) return undefined;
176
+ return segments;
177
+ }
178
+
179
+ export function trustedExecutableName(
180
+ command: string,
181
+ platform: PathPlatform,
182
+ ): string | undefined {
183
+ if (!command.includes("/") && !command.includes("\\")) {
184
+ return command.toLowerCase();
185
+ }
186
+ if (platform === "windows") {
187
+ if (!win32.isAbsolute(command)) return undefined;
188
+ const normalized = win32.normalize(command);
189
+ const directory = win32.dirname(normalized).toLowerCase();
190
+ if (
191
+ directory !== "c:\\windows\\system32"
192
+ && directory !== "c:\\program files\\powershell\\7"
193
+ ) return undefined;
194
+ return win32.basename(normalized).replace(/\.exe$/iu, "").toLowerCase();
195
+ }
196
+ if (!posix.isAbsolute(command)) return undefined;
197
+ const normalized = posix.normalize(command);
198
+ if (!TRUSTED_POSIX_EXECUTABLE_DIRECTORIES.has(posix.dirname(normalized))) {
199
+ return undefined;
200
+ }
201
+ return posix.basename(normalized).toLowerCase();
202
+ }
@@ -0,0 +1,16 @@
1
+ import { isRecord } from "@mupt-ai/dari-router/policy-engine";
2
+
3
+ import type { InteractionToolCall } from "../../interaction/types";
4
+
5
+ export function interactionToolInput(
6
+ item: InteractionToolCall,
7
+ ): Record<string, unknown> | undefined {
8
+ if (isRecord(item.input)) return item.input;
9
+ if (typeof item.input !== "string") return undefined;
10
+ try {
11
+ const parsed: unknown = JSON.parse(item.input);
12
+ return isRecord(parsed) ? parsed : undefined;
13
+ } catch {
14
+ return undefined;
15
+ }
16
+ }