@kindgi/handler-runtime 0.0.0-bootstrap.0 → 0.1.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 (68) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +218 -2
  3. package/dist/build-extensions.d.ts +75 -0
  4. package/dist/build-extensions.d.ts.map +1 -0
  5. package/dist/build-extensions.js +27 -0
  6. package/dist/build-extensions.js.map +1 -0
  7. package/dist/discovery.d.ts +19 -0
  8. package/dist/discovery.d.ts.map +1 -0
  9. package/dist/discovery.js +81 -0
  10. package/dist/discovery.js.map +1 -0
  11. package/dist/entrypoint.d.ts +10 -0
  12. package/dist/entrypoint.d.ts.map +1 -0
  13. package/dist/entrypoint.js +24 -0
  14. package/dist/entrypoint.js.map +1 -0
  15. package/dist/handler-runner.d.ts +127 -0
  16. package/dist/handler-runner.d.ts.map +1 -0
  17. package/dist/handler-runner.js +318 -0
  18. package/dist/handler-runner.js.map +1 -0
  19. package/dist/index.d.ts +8 -0
  20. package/dist/index.d.ts.map +1 -0
  21. package/dist/index.js +7 -0
  22. package/dist/index.js.map +1 -0
  23. package/dist/kindgi-index-main.d.ts +2 -0
  24. package/dist/kindgi-index-main.d.ts.map +1 -0
  25. package/dist/kindgi-index-main.js +15 -0
  26. package/dist/kindgi-index-main.js.map +1 -0
  27. package/dist/kindgi-index.d.ts +316 -0
  28. package/dist/kindgi-index.d.ts.map +1 -0
  29. package/dist/kindgi-index.js +1201 -0
  30. package/dist/kindgi-index.js.map +1 -0
  31. package/dist/pack-env.d.ts +66 -0
  32. package/dist/pack-env.d.ts.map +1 -0
  33. package/dist/pack-env.js +97 -0
  34. package/dist/pack-env.js.map +1 -0
  35. package/dist/pack-service/index.d.ts +7 -0
  36. package/dist/pack-service/index.d.ts.map +1 -0
  37. package/dist/pack-service/index.js +6 -0
  38. package/dist/pack-service/index.js.map +1 -0
  39. package/dist/pack-service/main.d.ts +47 -0
  40. package/dist/pack-service/main.d.ts.map +1 -0
  41. package/dist/pack-service/main.js +201 -0
  42. package/dist/pack-service/main.js.map +1 -0
  43. package/dist/pack-service/service.d.ts +61 -0
  44. package/dist/pack-service/service.d.ts.map +1 -0
  45. package/dist/pack-service/service.js +341 -0
  46. package/dist/pack-service/service.js.map +1 -0
  47. package/dist/pack-service/supervisor.d.ts +138 -0
  48. package/dist/pack-service/supervisor.d.ts.map +1 -0
  49. package/dist/pack-service/supervisor.js +424 -0
  50. package/dist/pack-service/supervisor.js.map +1 -0
  51. package/dist/protocol.d.ts +104 -0
  52. package/dist/protocol.d.ts.map +1 -0
  53. package/dist/protocol.js +116 -0
  54. package/dist/protocol.js.map +1 -0
  55. package/package.json +87 -4
  56. package/src/build-extensions.ts +100 -0
  57. package/src/discovery.ts +89 -0
  58. package/src/entrypoint.ts +23 -0
  59. package/src/handler-runner.ts +500 -0
  60. package/src/index.ts +66 -0
  61. package/src/kindgi-index-main.ts +17 -0
  62. package/src/kindgi-index.ts +1605 -0
  63. package/src/pack-env.ts +148 -0
  64. package/src/pack-service/index.ts +17 -0
  65. package/src/pack-service/main.ts +246 -0
  66. package/src/pack-service/service.ts +478 -0
  67. package/src/pack-service/supervisor.ts +600 -0
  68. package/src/protocol.ts +214 -0
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Whether the module at `moduleUrl` is the process entrypoint (`node <file>`).
3
+ *
4
+ * Node resolves symlinks for the main module's `import.meta.url` but leaves
5
+ * `process.argv[1]` as given, so the two are compared through the real path:
6
+ * a package started through `node_modules/@kindgi/…` (a pnpm symlink) still
7
+ * runs its `main()`.
8
+ */
9
+ export declare function isProcessEntrypoint(moduleUrl: string): boolean;
10
+ //# sourceMappingURL=entrypoint.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"entrypoint.d.ts","sourceRoot":"","sources":["../src/entrypoint.ts"],"names":[],"mappings":"AAMA;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAQ9D"}
@@ -0,0 +1,24 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ // Copyright (C) 2026 Kindgi Inc.
3
+ import { realpathSync } from 'node:fs';
4
+ import { pathToFileURL } from 'node:url';
5
+ /**
6
+ * Whether the module at `moduleUrl` is the process entrypoint (`node <file>`).
7
+ *
8
+ * Node resolves symlinks for the main module's `import.meta.url` but leaves
9
+ * `process.argv[1]` as given, so the two are compared through the real path:
10
+ * a package started through `node_modules/@kindgi/…` (a pnpm symlink) still
11
+ * runs its `main()`.
12
+ */
13
+ export function isProcessEntrypoint(moduleUrl) {
14
+ const entry = process.argv[1];
15
+ if (entry === undefined)
16
+ return false;
17
+ try {
18
+ return moduleUrl === pathToFileURL(realpathSync(entry)).href;
19
+ }
20
+ catch {
21
+ return false;
22
+ }
23
+ }
24
+ //# sourceMappingURL=entrypoint.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"entrypoint.js","sourceRoot":"","sources":["../src/entrypoint.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,iCAAiC;AAEjC,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC;;;;;;;GAOG;AACH,MAAM,UAAU,mBAAmB,CAAC,SAAiB;IACnD,MAAM,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAC9B,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,KAAK,CAAC;IACtC,IAAI,CAAC;QACH,OAAO,SAAS,KAAK,aAAa,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC;IAC/D,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC"}
@@ -0,0 +1,127 @@
1
+ import type { Result } from '@kindgi/types';
2
+ /**
3
+ * What a handler gets beside its input: the tenant and run it serves,
4
+ * and its resolved "typed needs" (env, secrets, config), composed by
5
+ * the server and sent with the call.
6
+ */
7
+ export interface HandlerContext {
8
+ readonly tenantId: string;
9
+ readonly runId: string;
10
+ readonly requestId?: string;
11
+ readonly env?: Readonly<Record<string, unknown>>;
12
+ readonly secrets?: Readonly<Record<string, unknown>>;
13
+ readonly config?: Readonly<Record<string, unknown>>;
14
+ /**
15
+ * Never on the wire; the pack service adds it: aborted when the call
16
+ * is cancelled or passes its deadline. Handlers that do slow I/O
17
+ * should pass it on so they stop promptly.
18
+ */
19
+ readonly abortSignal?: AbortSignal;
20
+ }
21
+ /**
22
+ * The tool being called, from the pack's `index.json` (the `kindgi-index`
23
+ * indexer writes it): its id, its module, and its JSON Schemas. The
24
+ * schemas are authoritative; a TypeScript type on the handler is not
25
+ * checked.
26
+ */
27
+ export interface ToolInvocationSpec {
28
+ readonly id: string;
29
+ readonly modulePath: string;
30
+ readonly inputSchema: Readonly<Record<string, unknown>>;
31
+ readonly outputSchema: Readonly<Record<string, unknown>>;
32
+ }
33
+ /**
34
+ * The guardrail check being called (`RegisteredCheck.evaluate(config,
35
+ * trace, bindings)`): its id and its module. The module's check is
36
+ * resolved like a handler (`default`, `check`, or a bare export with
37
+ * `evaluate`).
38
+ *
39
+ * A check in the pack service gets no callable bindings (no
40
+ * `providerRegistry`), so llm-judge checks run in the server, not here.
41
+ * It does get the call's `abortSignal`.
42
+ */
43
+ export interface CheckInvocationSpec {
44
+ readonly id: string;
45
+ readonly modulePath: string;
46
+ }
47
+ /** Every way a call can fail; the pack service answers with the same code. */
48
+ export type HandlerErrorCode = 'input-validation-failed' | 'output-validation-failed' | 'handler-import-failed' | 'handler-shape-invalid' | 'handler-throw' | 'check-shape-invalid';
49
+ export interface HandlerError {
50
+ readonly code: HandlerErrorCode;
51
+ readonly message: string;
52
+ readonly toolId?: string;
53
+ readonly cause?: unknown;
54
+ readonly issues?: readonly unknown[];
55
+ }
56
+ /**
57
+ * The handler surface — `handler(input, ctx)`. Return value may be
58
+ * either the raw output or a Promise thereof. Throwing is captured as
59
+ * a `handler-throw` error; a handler never takes down the process.
60
+ */
61
+ export type HandlerFn = (input: unknown, ctx: HandlerContext) => unknown | Promise<unknown>;
62
+ /**
63
+ * Shape the runner accepts back from a resolved handler module. The
64
+ * default `importHandler` accepts any of:
65
+ * - a bare function export (`export default (input, ctx) => ...`)
66
+ * - `{ default: HandlerFn }`
67
+ * - `{ handler: HandlerFn }`
68
+ * - `{ run: HandlerFn }` (the shape the sandbox entrypoint calls, so
69
+ * a single module can serve both)
70
+ */
71
+ export type HandlerModule = HandlerFn | {
72
+ readonly default: HandlerFn;
73
+ } | {
74
+ readonly handler: HandlerFn;
75
+ } | {
76
+ readonly run: HandlerFn;
77
+ };
78
+ export interface RunHandlerOptions {
79
+ readonly tool: ToolInvocationSpec;
80
+ readonly input: unknown;
81
+ readonly ctx: HandlerContext;
82
+ /**
83
+ * Override the default `import(modulePath)` resolver (tests). Return
84
+ * the same shape `HandlerModule` covers.
85
+ */
86
+ readonly importHandler?: (modulePath: string) => Promise<HandlerModule> | HandlerModule;
87
+ }
88
+ /**
89
+ * Run one tool call; a typed `Result`, never a throw — every failure is
90
+ * a `HandlerError`.
91
+ */
92
+ export declare function runHandler(options: RunHandlerOptions): Promise<Result<unknown, HandlerError>>;
93
+ /**
94
+ * Shape the runner accepts from a resolved check module. Analogous to
95
+ * `HandlerModule` — matches the `RegisteredCheck` shape (has `.evaluate`
96
+ * function) accessed via `default`, `check`, or bare export.
97
+ */
98
+ export type CheckModule = {
99
+ readonly evaluate: (...args: unknown[]) => unknown | Promise<unknown>;
100
+ } | {
101
+ readonly default: {
102
+ readonly evaluate: (...args: unknown[]) => unknown | Promise<unknown>;
103
+ } | ((...args: unknown[]) => unknown | Promise<unknown>);
104
+ } | {
105
+ readonly check: {
106
+ readonly evaluate: (...args: unknown[]) => unknown | Promise<unknown>;
107
+ } | ((...args: unknown[]) => unknown | Promise<unknown>);
108
+ };
109
+ export interface RunCheckOptions {
110
+ readonly check: CheckInvocationSpec;
111
+ readonly config: Readonly<Record<string, unknown>>;
112
+ readonly trace: unknown;
113
+ /**
114
+ * Aborted when the call is cancelled or passes its deadline; the
115
+ * check finds it as `bindings.abortSignal`.
116
+ */
117
+ readonly abortSignal?: AbortSignal;
118
+ readonly importCheck?: (modulePath: string) => Promise<CheckModule> | CheckModule;
119
+ }
120
+ /**
121
+ * Run one guardrail check: `evaluate(config, trace, bindings)`, where
122
+ * `bindings` carries only the call's `abortSignal` (no provider
123
+ * registry, so no llm-judge checks here). A typed `Result`, never a
124
+ * throw — every failure is a `HandlerError`.
125
+ */
126
+ export declare function runCheck(options: RunCheckOptions): Promise<Result<unknown, HandlerError>>;
127
+ //# sourceMappingURL=handler-runner.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handler-runner.d.ts","sourceRoot":"","sources":["../src/handler-runner.ts"],"names":[],"mappings":"AA+BA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAE5C;;;;GAIG;AACH,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,GAAG,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IACjD,QAAQ,CAAC,OAAO,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IACrD,QAAQ,CAAC,MAAM,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IACpD;;;;OAIG;IACH,QAAQ,CAAC,WAAW,CAAC,EAAE,WAAW,CAAC;CACpC;AAED;;;;;GAKG;AACH,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,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O,CAAC;IACxB;;;OAGG;IACH,QAAQ,CAAC,WAAW,CAAC,EAAE,WAAW,CAAC;IACnC,QAAQ,CAAC,WAAW,CAAC,EAAE,CAAC,UAAU,EAAE,MAAM,KAAK,OAAO,CAAC,WAAW,CAAC,GAAG,WAAW,CAAC;CACnF;AAED;;;;;GAKG;AACH,wBAAsB,QAAQ,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,MAAM,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC,CAiD/F"}
@@ -0,0 +1,318 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ // Copyright (C) 2026 Kindgi Inc.
3
+ import * as addFormatsModule from 'ajv-formats';
4
+ import { Ajv2020 } from 'ajv/dist/2020.js';
5
+ import { isZodSchema, parseWithSchema } from '@kindgi/schema';
6
+ const addFormatsRaw = addFormatsModule;
7
+ const addFormats = typeof addFormatsRaw === 'function'
8
+ ? addFormatsRaw
9
+ : addFormatsRaw.default;
10
+ /** Compiled validators by side and schema, oldest first; see `compileSchema`. */
11
+ const compiledValidators = new Map();
12
+ /** Enough for every schema of a large pack, a few edits over. */
13
+ const MAX_COMPILED_VALIDATORS = 512;
14
+ /**
15
+ * The ajv validator for a JSON Schema — compiled once per side and
16
+ * schema, then reused: a pack service validates every call of a tool
17
+ * against the same two schemas, and compiling is the cost. An edited
18
+ * schema is a new key, so a hot reload takes effect. A validator is
19
+ * shared by concurrent calls safely: validation is synchronous.
20
+ */
21
+ function compileSchema(schema, side) {
22
+ const key = `${side}:${JSON.stringify(schema)}`;
23
+ const cached = compiledValidators.get(key);
24
+ if (cached !== undefined)
25
+ return cached;
26
+ // An input validator fills in each property's JSON Schema `default`;
27
+ // it checks a copy of the caller's input.
28
+ const ajv = new Ajv2020({
29
+ strict: true,
30
+ allErrors: true,
31
+ allowUnionTypes: false,
32
+ ...(side === 'input' && { useDefaults: true }),
33
+ });
34
+ addFormats(ajv);
35
+ const validator = ajv.compile(schema);
36
+ if (compiledValidators.size >= MAX_COMPILED_VALIDATORS) {
37
+ const oldest = compiledValidators.keys().next().value;
38
+ if (oldest !== undefined)
39
+ compiledValidators.delete(oldest);
40
+ }
41
+ compiledValidators.set(key, validator);
42
+ return validator;
43
+ }
44
+ /**
45
+ * Run one tool call; a typed `Result`, never a throw — every failure is
46
+ * a `HandlerError`.
47
+ */
48
+ export async function runHandler(options) {
49
+ const { tool, input, ctx } = options;
50
+ const importHandler = options.importHandler ?? defaultImportHandler;
51
+ let inputValidator;
52
+ try {
53
+ inputValidator = compileSchema(tool.inputSchema, 'input');
54
+ }
55
+ catch (cause) {
56
+ return {
57
+ kind: 'err',
58
+ error: {
59
+ code: 'input-validation-failed',
60
+ message: `Tool "${tool.id}" input schema failed to compile: ${stringifyError(cause)}`,
61
+ toolId: tool.id,
62
+ cause: serializeCause(cause),
63
+ },
64
+ };
65
+ }
66
+ const candidate = structuredClone(input);
67
+ if (!inputValidator(candidate)) {
68
+ return {
69
+ kind: 'err',
70
+ error: {
71
+ code: 'input-validation-failed',
72
+ message: `Tool "${tool.id}" input failed validation`,
73
+ toolId: tool.id,
74
+ issues: inputValidator.errors ?? [],
75
+ },
76
+ };
77
+ }
78
+ let module_;
79
+ try {
80
+ module_ = await importHandler(tool.modulePath);
81
+ }
82
+ catch (cause) {
83
+ return {
84
+ kind: 'err',
85
+ error: {
86
+ code: 'handler-import-failed',
87
+ message: `Failed to import handler module '${tool.modulePath}': ${stringifyError(cause)}`,
88
+ toolId: tool.id,
89
+ cause: serializeCause(cause),
90
+ },
91
+ };
92
+ }
93
+ const handler = resolveHandler(module_);
94
+ const inputZod = resolveInputZod(module_);
95
+ if (handler === undefined) {
96
+ return {
97
+ kind: 'err',
98
+ error: {
99
+ code: 'handler-shape-invalid',
100
+ message: `Handler module '${tool.modulePath}' does not export a handler function (looked for default / handler / run)`,
101
+ toolId: tool.id,
102
+ },
103
+ };
104
+ }
105
+ // A Zod-authored tool gets its parsed input: defaults, transforms and
106
+ // refinements applied, as its handler's type says.
107
+ let prepared = candidate;
108
+ if (inputZod !== undefined) {
109
+ const parsed = await parseWithSchema(inputZod, candidate);
110
+ if (parsed.kind === 'err') {
111
+ return {
112
+ kind: 'err',
113
+ error: {
114
+ code: 'input-validation-failed',
115
+ message: `Tool "${tool.id}" input failed validation`,
116
+ toolId: tool.id,
117
+ issues: parsed.issues.map((i) => ({
118
+ instancePath: (i.path ?? []).map((p) => `/${String(p)}`).join(''),
119
+ message: i.message,
120
+ })),
121
+ },
122
+ };
123
+ }
124
+ prepared = parsed.value;
125
+ }
126
+ let output;
127
+ try {
128
+ output = await handler(prepared, ctx);
129
+ }
130
+ catch (cause) {
131
+ return {
132
+ kind: 'err',
133
+ error: {
134
+ code: 'handler-throw',
135
+ message: `Handler for tool "${tool.id}" threw: ${stringifyError(cause)}`,
136
+ toolId: tool.id,
137
+ cause: serializeCause(cause),
138
+ },
139
+ };
140
+ }
141
+ let outputValidator;
142
+ try {
143
+ outputValidator = compileSchema(tool.outputSchema, 'output');
144
+ }
145
+ catch (cause) {
146
+ return {
147
+ kind: 'err',
148
+ error: {
149
+ code: 'output-validation-failed',
150
+ message: `Tool "${tool.id}" output schema failed to compile: ${stringifyError(cause)}`,
151
+ toolId: tool.id,
152
+ cause: serializeCause(cause),
153
+ },
154
+ };
155
+ }
156
+ if (!outputValidator(output)) {
157
+ return {
158
+ kind: 'err',
159
+ error: {
160
+ code: 'output-validation-failed',
161
+ message: `Tool "${tool.id}" handler produced output that failed validation`,
162
+ toolId: tool.id,
163
+ issues: outputValidator.errors ?? [],
164
+ },
165
+ };
166
+ }
167
+ return { kind: 'ok', value: output };
168
+ }
169
+ /**
170
+ * Run one guardrail check: `evaluate(config, trace, bindings)`, where
171
+ * `bindings` carries only the call's `abortSignal` (no provider
172
+ * registry, so no llm-judge checks here). A typed `Result`, never a
173
+ * throw — every failure is a `HandlerError`.
174
+ */
175
+ export async function runCheck(options) {
176
+ const { check, config, trace } = options;
177
+ const importCheck = options.importCheck ?? defaultImportCheck;
178
+ let module_;
179
+ try {
180
+ module_ = await importCheck(check.modulePath);
181
+ }
182
+ catch (cause) {
183
+ return {
184
+ kind: 'err',
185
+ error: {
186
+ code: 'handler-import-failed',
187
+ message: `Failed to import check module '${check.modulePath}': ${stringifyError(cause)}`,
188
+ toolId: check.id,
189
+ cause: serializeCause(cause),
190
+ },
191
+ };
192
+ }
193
+ const evaluate = resolveCheckEvaluate(module_);
194
+ if (evaluate === undefined) {
195
+ return {
196
+ kind: 'err',
197
+ error: {
198
+ code: 'check-shape-invalid',
199
+ message: `Check module '${check.modulePath}' does not export a check with .evaluate() (looked for default / check / bare export with evaluate)`,
200
+ toolId: check.id,
201
+ },
202
+ };
203
+ }
204
+ let result;
205
+ try {
206
+ result = await evaluate(config, trace, {
207
+ ...(options.abortSignal !== undefined && { abortSignal: options.abortSignal }),
208
+ });
209
+ }
210
+ catch (cause) {
211
+ return {
212
+ kind: 'err',
213
+ error: {
214
+ code: 'handler-throw',
215
+ message: `Check "${check.id}" evaluate() threw: ${stringifyError(cause)}`,
216
+ toolId: check.id,
217
+ cause: serializeCause(cause),
218
+ },
219
+ };
220
+ }
221
+ return { kind: 'ok', value: result };
222
+ }
223
+ function resolveCheckEvaluate(module_) {
224
+ const candidates = [
225
+ module_.evaluate,
226
+ module_.default,
227
+ module_.check,
228
+ ];
229
+ for (const candidate of candidates) {
230
+ if (candidate === undefined || candidate === null)
231
+ continue;
232
+ if (typeof candidate === 'function') {
233
+ return candidate;
234
+ }
235
+ const nested = candidate.evaluate;
236
+ if (typeof nested === 'function') {
237
+ return nested;
238
+ }
239
+ }
240
+ return undefined;
241
+ }
242
+ async function defaultImportCheck(modulePath) {
243
+ return (await import(modulePath));
244
+ }
245
+ /** The Zod input schema of a `defineTool` export (`inputZod`), when the module has one. */
246
+ function resolveInputZod(module_) {
247
+ if (typeof module_ !== 'object' || module_ === null)
248
+ return undefined;
249
+ const record = module_;
250
+ for (const candidate of [record.default, record.handler, record.run]) {
251
+ if (typeof candidate !== 'object' || candidate === null)
252
+ continue;
253
+ const inputZod = candidate.inputZod;
254
+ if (isZodSchema(inputZod))
255
+ return inputZod;
256
+ }
257
+ return undefined;
258
+ }
259
+ function resolveHandler(module_) {
260
+ if (typeof module_ === 'function')
261
+ return module_;
262
+ if (typeof module_ !== 'object' || module_ === null)
263
+ return undefined;
264
+ const record = module_;
265
+ const candidates = [record.default, record.handler, record.run];
266
+ for (const candidate of candidates) {
267
+ if (candidate === undefined || candidate === null)
268
+ continue;
269
+ if (typeof candidate === 'function')
270
+ return candidate;
271
+ // `export default defineTool({..., handler: fn})` — the export is
272
+ // a Tool object; the callable lives at `.handler` (or `.run` for
273
+ // the sandbox-entrypoint shape). Walk one level in before giving up.
274
+ if (typeof candidate === 'object') {
275
+ const nested = candidate;
276
+ if (typeof nested.handler === 'function')
277
+ return nested.handler;
278
+ if (typeof nested.run === 'function')
279
+ return nested.run;
280
+ }
281
+ }
282
+ return undefined;
283
+ }
284
+ async function defaultImportHandler(modulePath) {
285
+ return (await import(modulePath));
286
+ }
287
+ function stringifyError(err) {
288
+ if (err instanceof Error)
289
+ return `${err.name}: ${err.message}`;
290
+ return String(err);
291
+ }
292
+ /**
293
+ * Handlers may throw arbitrary values (Error, string, plain objects,
294
+ * undefined). The wire protocol carries `cause` as JSON — serialize to
295
+ * a shape JSON.stringify handles cleanly. Preserve the original message
296
+ * + name when `err` is an Error; fall back to a stringified rep otherwise.
297
+ */
298
+ function serializeCause(err) {
299
+ if (err instanceof Error) {
300
+ return { name: err.name, message: err.message, stack: err.stack };
301
+ }
302
+ if (err === undefined)
303
+ return null;
304
+ if (err === null ||
305
+ typeof err === 'string' ||
306
+ typeof err === 'number' ||
307
+ typeof err === 'boolean') {
308
+ return err;
309
+ }
310
+ try {
311
+ JSON.stringify(err);
312
+ return err;
313
+ }
314
+ catch {
315
+ return String(err);
316
+ }
317
+ }
318
+ //# sourceMappingURL=handler-runner.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handler-runner.js","sourceRo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n, HandlerModule, RunCheckOptions, RunHandlerOptions, ToolInvocationSpec, } from './handler-runner.js';
2
+ export { runCheck, runHandler } from './handler-runner.js';
3
+ export type { DiscoveryConfig, Index, IndexedAgent, IndexedFlow, IndexedGuardrail, IndexedTool, IndexEnvelopeVersion, IndexerError, IndexerErrorCode, IndexerReport, PrimitiveKind, RunIndexerOptions, KindgiConfig, KindgiConfigFile, LoadKindgiConfigOptions, PackLanguage, } from './kindgi-index.js';
4
+ export { DEFAULT_DISCOVERY, DEFAULT_PYTHON_DISCOVERY, HELP_TEXT as KINDGI_INDEX_HELP_TEXT, INDEX_ENVELOPE_VERSION, KERNEL_PAYLOAD_VERSION, KINDGI_CONFIG_FILENAMES, PYPROJECT_FILENAME, findKindgiConfig, loadKindgiConfig, packLanguage, resolveDiscovery, main as kindgiIndexMain, runIndexer, } from './kindgi-index.js';
5
+ export type { PackEnvCheck, PackEnvConfig, PackEnvDeclaration, PackEnvResult } from './pack-env.js';
6
+ export { PACK_ENV_CHECK_VAR, PACK_ENV_NAME, RESERVED_ENV_PREFIX, missingPackEnv, parsePackEnvCheck, resolvePackEnv, } from './pack-env.js';
7
+ export { TEST_FILE_REGEX, createGlobMatcher, discoveryRoots, globStaticPrefix, globToRegex, } from './discovery.js';
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,YAAY,EACV,mBAAmB,EACnB,WAAW,EACX,cAAc,EACd,YAAY,EACZ,gBAAgB,EAChB,SAAS,EACT,aAAa,EACb,eAAe,EACf,iBAAiB,EACjB,kBAAkB,GACnB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAE3D,YAAY,EACV,eAAe,EACf,KAAK,EACL,YAAY,EACZ,WAAW,EACX,gBAAgB,EAChB,WAAW,EACX,oBAAoB,EACpB,YAAY,EACZ,gBAAgB,EAChB,aAAa,EACb,aAAa,EACb,iBAAiB,EACjB,YAAY,EACZ,gBAAgB,EAChB,uBAAuB,EACvB,YAAY,GACb,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,iBAAiB,EACjB,wBAAwB,EACxB,SAAS,IAAI,sBAAsB,EACnC,sBAAsB,EACtB,sBAAsB,EACtB,uBAAuB,EACvB,kBAAkB,EAClB,gBAAgB,EAChB,gBAAgB,EAChB,YAAY,EACZ,gBAAgB,EAChB,IAAI,IAAI,eAAe,EACvB,UAAU,GACX,MAAM,mBAAmB,CAAC;AAC3B,YAAY,EAAE,YAAY,EAAE,aAAa,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AACpG,OAAO,EACL,kBAAkB,EAClB,aAAa,EACb,mBAAmB,EACnB,cAAc,EACd,iBAAiB,EACjB,cAAc,GACf,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,eAAe,EACf,iBAAiB,EACjB,cAAc,EACd,gBAAgB,EAChB,WAAW,GACZ,MAAM,gBAAgB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,7 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ // Copyright (C) 2026 Kindgi Inc.
3
+ export { runCheck, runHandler } from './handler-runner.js';
4
+ export { DEFAULT_DISCOVERY, DEFAULT_PYTHON_DISCOVERY, HELP_TEXT as KINDGI_INDEX_HELP_TEXT, INDEX_ENVELOPE_VERSION, KERNEL_PAYLOAD_VERSION, KINDGI_CONFIG_FILENAMES, PYPROJECT_FILENAME, findKindgiConfig, loadKindgiConfig, packLanguage, resolveDiscovery, main as kindgiIndexMain, runIndexer, } from './kindgi-index.js';
5
+ export { PACK_ENV_CHECK_VAR, PACK_ENV_NAME, RESERVED_ENV_PREFIX, missingPackEnv, parsePackEnvCheck, resolvePackEnv, } from './pack-env.js';
6
+ export { TEST_FILE_REGEX, createGlobMatcher, discoveryRoots, globStaticPrefix, globToRegex, } from './discovery.js';
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,iCAAiC;AAcjC,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAoB3D,OAAO,EACL,iBAAiB,EACjB,wBAAwB,EACxB,SAAS,IAAI,sBAAsB,EACnC,sBAAsB,EACtB,sBAAsB,EACtB,uBAAuB,EACvB,kBAAkB,EAClB,gBAAgB,EAChB,gBAAgB,EAChB,YAAY,EACZ,gBAAgB,EAChB,IAAI,IAAI,eAAe,EACvB,UAAU,GACX,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EACL,kBAAkB,EAClB,aAAa,EACb,mBAAmB,EACnB,cAAc,EACd,iBAAiB,EACjB,cAAc,GACf,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,eAAe,EACf,iBAAiB,EACjB,cAAc,EACd,gBAAgB,EAChB,WAAW,GACZ,MAAM,gBAAgB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=kindgi-index-main.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"kindgi-index-main.d.ts","sourceRoot":"","sources":["../src/kindgi-index-main.ts"],"names":[],"mappings":""}
@@ -0,0 +1,15 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ // Copyright (C) 2026 Kindgi Inc.
3
+ /**
4
+ * The `kindgi-index` process: `node <this file> --pack-dir … [--bundle-map …]`
5
+ * (package export `@kindgi/handler-runtime/kindgi-index-main`). A pack
6
+ * image's indexer stage runs it, bundled as `dist/kindgi-index.mjs`.
7
+ *
8
+ * A module of its own that runs `main()` as it loads, rather than a
9
+ * process-entry check inside `kindgi-index.ts`: bundled, every module in
10
+ * a bundle shares the bundle's `import.meta.url`, so such a check would
11
+ * also fire in the pack service's bundle, which imports `kindgi-index`.
12
+ */
13
+ import { main } from './kindgi-index.js';
14
+ process.exitCode = await main(process.argv.slice(2));
15
+ //# sourceMappingURL=kindgi-index-main.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"kindgi-index-main.js","sourceRoot":"","sources":["../src/kindgi-index-main.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,iCAAiC;AAEjC;;;;;;;;;GASG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAEzC,OAAO,CAAC,QAAQ,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC"}