@caplets/core 0.19.0 → 0.20.1
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/dist/auth.d.ts +2 -2
- package/dist/caplet-files-bundle.d.ts +24 -9
- package/dist/caplet-source.js +368 -4588
- package/dist/cli/auth.d.ts +40 -2
- package/dist/cli/cloud-add.d.ts +8 -0
- package/dist/cli/code-mode.d.ts +16 -0
- package/dist/cli/commands.d.ts +3 -1
- package/dist/cli/doctor.d.ts +3 -0
- package/dist/cli/setup.d.ts +7 -0
- package/dist/cli-tools.d.ts +1 -1
- package/dist/cli.d.ts +1 -0
- package/dist/cloud-auth/client.d.ts +15 -0
- package/dist/cloud-auth/types.d.ts +2 -1
- package/dist/code-mode/api.d.ts +32 -0
- package/dist/code-mode/declarations.d.ts +5 -0
- package/dist/code-mode/diagnostics.d.ts +8 -0
- package/dist/code-mode/index.d.ts +4 -0
- package/dist/code-mode/logs.d.ts +21 -0
- package/dist/code-mode/runner.d.ts +15 -0
- package/dist/code-mode/runtime-api.generated.d.ts +1 -0
- package/dist/code-mode/sandbox.d.ts +28 -0
- package/dist/code-mode/static-analysis.d.ts +2 -0
- package/dist/code-mode/tool.d.ts +11 -0
- package/dist/code-mode/types.d.ts +120 -0
- package/dist/code-mode.js +147855 -0
- package/dist/{completion-brgziz4L.js → completion-D-kuyArL.js} +5 -2
- package/dist/config/paths.d.ts +2 -0
- package/dist/config-runtime.d.ts +13 -4
- package/dist/config-runtime.js +31 -2
- package/dist/config.d.ts +34 -9
- package/dist/downstream.d.ts +20 -2
- package/dist/engine.d.ts +20 -0
- package/dist/exposure/direct-names.d.ts +9 -0
- package/dist/exposure/discovery.d.ts +75 -0
- package/dist/exposure/policy.d.ts +8 -0
- package/dist/generated-tool-input-schema.d.ts +89 -59
- package/dist/generated-tool-input-schema.js +38 -27
- package/dist/graphql.d.ts +1 -1
- package/dist/http-actions.d.ts +1 -1
- package/dist/index.d.ts +13 -0
- package/dist/index.js +1096 -154
- package/dist/native/service.d.ts +6 -0
- package/dist/native/tools.d.ts +2 -0
- package/dist/native.d.ts +1 -1
- package/dist/native.js +2 -2
- package/dist/observed-output-shapes/extract.d.ts +5 -0
- package/dist/observed-output-shapes/file-store.d.ts +17 -0
- package/dist/observed-output-shapes/index.d.ts +7 -0
- package/dist/observed-output-shapes/key.d.ts +14 -0
- package/dist/observed-output-shapes/merge.d.ts +2 -0
- package/dist/observed-output-shapes/pure.d.ts +5 -0
- package/dist/observed-output-shapes/pure.js +241 -0
- package/dist/observed-output-shapes/schema.d.ts +1 -0
- package/dist/observed-output-shapes/types.d.ts +84 -0
- package/dist/observed-output-shapes/typescript.d.ts +7 -0
- package/dist/observed-output-shapes-uzAMQPhg.js +485 -0
- package/dist/observed-output-shapes.js +2 -0
- package/dist/openapi.d.ts +1 -1
- package/dist/project-binding/index.d.ts +2 -0
- package/dist/project-binding.js +22 -0
- package/dist/redaction.d.ts +14 -0
- package/dist/redaction.js +30 -0
- package/dist/registry.d.ts +4 -0
- package/dist/remote/options.d.ts +2 -0
- package/dist/remote-control/types.d.ts +1 -1
- package/dist/runtime-plan/resources.d.ts +2 -0
- package/dist/runtime-plan.js +8 -2
- package/dist/schemas-1HZ0kFpx.js +4270 -0
- package/dist/serve/session.d.ts +15 -3
- package/dist/{service-BXcE4Rv8.js → service-Bsq7R0mt.js} +29312 -26554
- package/dist/stable-json.d.ts +3 -0
- package/dist/stable-json.js +26 -0
- package/dist/tools.d.ts +22 -11
- package/dist/{validation-BBG4skZf.js → validation-CdqbI2zN.js} +25 -4
- package/package.json +29 -3
package/dist/native/service.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { NativeCapletsServiceResolutionInput } from "./options";
|
|
2
2
|
import { resolveNativeCapletsServiceOptions } from "./options";
|
|
3
3
|
import { type RemoteCapletsClient } from "./remote";
|
|
4
|
+
import type { CodeModeCallableCaplet } from "../code-mode/types";
|
|
4
5
|
import { type CapletsConfig } from "../config";
|
|
5
6
|
import { generatedToolInputJsonSchemaForCaplet } from "../generated-tool-input-schema";
|
|
6
7
|
export type NativeCapletsServiceOptions = NativeCapletsServiceResolutionInput & {
|
|
@@ -18,9 +19,14 @@ export type NativeCapletTool = {
|
|
|
18
19
|
toolName: string;
|
|
19
20
|
title: string;
|
|
20
21
|
description: string;
|
|
22
|
+
codeModeRun?: boolean;
|
|
23
|
+
useWhen?: string;
|
|
24
|
+
avoidWhen?: string;
|
|
21
25
|
promptGuidance: string[];
|
|
22
26
|
inputSchema?: ReturnType<typeof generatedToolInputJsonSchemaForCaplet> | Record<string, unknown>;
|
|
27
|
+
outputSchema?: Record<string, unknown>;
|
|
23
28
|
operationNames?: string[];
|
|
29
|
+
codeModeCaplets?: CodeModeCallableCaplet[];
|
|
24
30
|
};
|
|
25
31
|
export type NativeCapletsToolsChangedListener = (tools: NativeCapletTool[]) => void;
|
|
26
32
|
export type NativeCapletsService = {
|
package/dist/native/tools.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import type { CapletConfig } from "../config";
|
|
2
|
+
export declare const nativeCodeModeToolId = "code_mode";
|
|
3
|
+
export declare const nativeCodeModeToolName = "caplets__code_mode";
|
|
2
4
|
export declare function nativeCapletToolName(capletId: string): string;
|
|
3
5
|
export declare function nativeCapletsSystemGuidance(toolNames: string[]): string;
|
|
4
6
|
export declare function nativeCapletPromptGuidance(toolName: string, caplet: CapletConfig): string[];
|
package/dist/native.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { createNativeCapletsService, type NativeCapletTool, type NativeCapletsService, type NativeCapletsServiceOptions, type NativeCapletsToolsChangedListener, } from "./native/service";
|
|
2
2
|
export { registerNativeCapletsProcessCleanup, type NativeCapletsProcessCleanupOptions, } from "./native/process-cleanup";
|
|
3
|
-
export { nativeCapletPromptGuidance, nativeCapletToolDescription, nativeCapletToolName, nativeCapletsSystemGuidance, } from "./native/tools";
|
|
3
|
+
export { nativeCapletPromptGuidance, nativeCapletToolDescription, nativeCapletToolName, nativeCapletsSystemGuidance, nativeCodeModeToolId, nativeCodeModeToolName, } from "./native/tools";
|
|
4
4
|
export { generatedToolInputSchema } from "./tools";
|
|
5
5
|
export { generatedToolInputJsonSchema } from "./generated-tool-input-schema";
|
|
6
6
|
export { resolveNativeCapletsServiceOptions, type NativeCapletsEnv, type NativeCapletsMode, type NativeCapletsServiceResolutionInput, type NativeRemoteAuthOptions, type NativeRemoteCapletsOptions, type ResolvedNativeCapletsServiceOptions, } from "./native/options";
|
package/dist/native.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { C as nativeCapletToolName, E as nativeCodeModeToolName, S as nativeCapletToolDescription, T as nativeCodeModeToolId, f as RemoteNativeCapletsService, h as resolveNativeCapletsServiceOptions, p as createSdkRemoteCapletsClient, t as createNativeCapletsService, w as nativeCapletsSystemGuidance, x as nativeCapletPromptGuidance } from "./service-Bsq7R0mt.js";
|
|
2
2
|
import { generatedToolInputJsonSchema, generatedToolInputSchema } from "./generated-tool-input-schema.js";
|
|
3
3
|
//#region src/native/process-cleanup.ts
|
|
4
4
|
function registerNativeCapletsProcessCleanup(service, options = {}) {
|
|
@@ -29,4 +29,4 @@ function errorMessage(error) {
|
|
|
29
29
|
return error instanceof Error ? error.message : String(error);
|
|
30
30
|
}
|
|
31
31
|
//#endregion
|
|
32
|
-
export { RemoteNativeCapletsService, createNativeCapletsService, createSdkRemoteCapletsClient, generatedToolInputJsonSchema, generatedToolInputSchema, nativeCapletPromptGuidance, nativeCapletToolDescription, nativeCapletToolName, nativeCapletsSystemGuidance, registerNativeCapletsProcessCleanup, resolveNativeCapletsServiceOptions };
|
|
32
|
+
export { RemoteNativeCapletsService, createNativeCapletsService, createSdkRemoteCapletsClient, generatedToolInputJsonSchema, generatedToolInputSchema, nativeCapletPromptGuidance, nativeCapletToolDescription, nativeCapletToolName, nativeCapletsSystemGuidance, nativeCodeModeToolId, nativeCodeModeToolName, registerNativeCapletsProcessCleanup, resolveNativeCapletsServiceOptions };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type ExtractObservedOutputShapeInput, type JsonShape, type ObservedOutputShape } from "./types";
|
|
2
|
+
export declare function observeOutputShape(input: ExtractObservedOutputShapeInput): ObservedOutputShape | undefined;
|
|
3
|
+
export declare function extractJsonShape(value: unknown): JsonShape | undefined;
|
|
4
|
+
export declare function parseShapeableJsonText(value: unknown): unknown | undefined;
|
|
5
|
+
export declare function normalizedObservableValue(result: unknown): unknown | undefined;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type ObservedOutputShape, type ObservedOutputShapeKey, type ObservedOutputShapePruneResult, type ObservedOutputShapeStore, type ObservedOutputShapeStoreHealth } from "./types";
|
|
2
|
+
export declare class FileObservedOutputShapeStore implements ObservedOutputShapeStore {
|
|
3
|
+
private readonly cacheDir;
|
|
4
|
+
private readonly options;
|
|
5
|
+
constructor(cacheDir: string, options?: {
|
|
6
|
+
ttlMs?: number | undefined;
|
|
7
|
+
maxEntries?: number | undefined;
|
|
8
|
+
});
|
|
9
|
+
read(key: ObservedOutputShapeKey): Promise<ObservedOutputShape | undefined>;
|
|
10
|
+
write(key: ObservedOutputShapeKey, shape: ObservedOutputShape): Promise<void>;
|
|
11
|
+
prune(now?: Date): Promise<ObservedOutputShapePruneResult>;
|
|
12
|
+
health(): Promise<ObservedOutputShapeStoreHealth>;
|
|
13
|
+
private pathFor;
|
|
14
|
+
private entries;
|
|
15
|
+
private ttlMs;
|
|
16
|
+
private maxEntries;
|
|
17
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { FileObservedOutputShapeStore } from "./file-store";
|
|
2
|
+
export { extractJsonShape, normalizedObservableValue, observeOutputShape, parseShapeableJsonText, } from "./extract";
|
|
3
|
+
export { backendFingerprint, observedOutputShapeKey, observedOutputShapeStorageKey, stableHash, } from "./key";
|
|
4
|
+
export { mergeJsonShapes } from "./merge";
|
|
5
|
+
export { usefulOutputSchema } from "./schema";
|
|
6
|
+
export { hasTruncatedShape, shapeToTypeScript, shapeType } from "./typescript";
|
|
7
|
+
export { OBSERVED_OUTPUT_SHAPE_LIMITS, OBSERVED_OUTPUT_SHAPE_VERSION, type JsonShape, type ObservedOutputShape, type ObservedOutputShapeKey, type ObservedOutputShapePruneResult, type ObservedOutputShapeStore, type ObservedOutputShapeStoreHealth, } from "./types";
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { CapletConfig } from "../config";
|
|
2
|
+
import { type ObservedOutputShapeKey } from "./types";
|
|
3
|
+
export declare function observedOutputShapeStorageKey(key: ObservedOutputShapeKey): string;
|
|
4
|
+
export declare function observedOutputShapeKey(input: {
|
|
5
|
+
scope: ObservedOutputShapeKey["scope"];
|
|
6
|
+
workspaceId?: string | undefined;
|
|
7
|
+
projectFingerprint?: string | undefined;
|
|
8
|
+
caplet: CapletConfig;
|
|
9
|
+
toolName: string;
|
|
10
|
+
toolDescriptor?: unknown;
|
|
11
|
+
outputSchema?: unknown;
|
|
12
|
+
}): ObservedOutputShapeKey;
|
|
13
|
+
export declare function backendFingerprint(caplet: CapletConfig): string;
|
|
14
|
+
export declare function stableHash(value: unknown): string;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { extractJsonShape, normalizedObservableValue, observeOutputShape, parseShapeableJsonText, } from "./extract";
|
|
2
|
+
export { mergeJsonShapes } from "./merge";
|
|
3
|
+
export { usefulOutputSchema } from "./schema";
|
|
4
|
+
export { hasTruncatedShape, shapeToTypeScript, shapeType } from "./typescript";
|
|
5
|
+
export { OBSERVED_OUTPUT_SHAPE_LIMITS, OBSERVED_OUTPUT_SHAPE_VERSION, type JsonShape, type ObservedOutputShape, type ExtractObservedOutputShapeInput, } from "./types";
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
//#region src/observed-output-shapes/types.ts
|
|
2
|
+
const OBSERVED_OUTPUT_SHAPE_VERSION = 1;
|
|
3
|
+
const OBSERVED_OUTPUT_SHAPE_LIMITS = {
|
|
4
|
+
maxDepth: 6,
|
|
5
|
+
maxObjectFields: 40,
|
|
6
|
+
maxArrayElements: 20,
|
|
7
|
+
maxUnionVariants: 4,
|
|
8
|
+
maxTypeScriptChars: 4e3,
|
|
9
|
+
maxStoredJsonBytes: 16e3,
|
|
10
|
+
ttlMs: 720 * 60 * 60 * 1e3,
|
|
11
|
+
maxLocalEntries: 2e3
|
|
12
|
+
};
|
|
13
|
+
//#endregion
|
|
14
|
+
//#region src/observed-output-shapes/merge.ts
|
|
15
|
+
function mergeJsonShapes(left, right) {
|
|
16
|
+
if (left.kind === "unknown" || right.kind === "unknown") return { kind: "unknown" };
|
|
17
|
+
if (left.kind === right.kind) {
|
|
18
|
+
if (left.kind === "object" && right.kind === "object") return mergeObjects(left, right);
|
|
19
|
+
if (left.kind === "array" && right.kind === "array") return mergeArrays(left, right);
|
|
20
|
+
if (left.kind === "union" && right.kind === "union") return boundedUnion([...left.variants, ...right.variants]);
|
|
21
|
+
return left;
|
|
22
|
+
}
|
|
23
|
+
return boundedUnion([...left.kind === "union" ? left.variants : [left], ...right.kind === "union" ? right.variants : [right]]);
|
|
24
|
+
}
|
|
25
|
+
function mergeObjects(left, right) {
|
|
26
|
+
const fields = {};
|
|
27
|
+
const keys = [...new Set([...Object.keys(left.fields), ...Object.keys(right.fields)])].sort();
|
|
28
|
+
let truncated = left.truncated === true || right.truncated === true;
|
|
29
|
+
const selected = keys.slice(0, OBSERVED_OUTPUT_SHAPE_LIMITS.maxObjectFields);
|
|
30
|
+
truncated = truncated || keys.length > selected.length;
|
|
31
|
+
for (const key of selected) {
|
|
32
|
+
const leftField = left.fields[key];
|
|
33
|
+
const rightField = right.fields[key];
|
|
34
|
+
if (leftField && rightField) fields[key] = {
|
|
35
|
+
optional: true,
|
|
36
|
+
shape: mergeJsonShapes(leftField.shape, rightField.shape)
|
|
37
|
+
};
|
|
38
|
+
else fields[key] = {
|
|
39
|
+
optional: true,
|
|
40
|
+
shape: (leftField ?? rightField).shape
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
return {
|
|
44
|
+
kind: "object",
|
|
45
|
+
fields,
|
|
46
|
+
...truncated ? { truncated: true } : {}
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
function mergeArrays(left, right) {
|
|
50
|
+
const element = left.element && right.element ? mergeJsonShapes(left.element, right.element) : left.element ?? right.element;
|
|
51
|
+
return {
|
|
52
|
+
kind: "array",
|
|
53
|
+
...element ? { element } : {},
|
|
54
|
+
...left.truncated === true || right.truncated === true ? { truncated: true } : {}
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
function boundedUnion(variants) {
|
|
58
|
+
const flattened = variants.flatMap((variant) => variant.kind === "union" ? variant.variants : [variant]);
|
|
59
|
+
const unique = [];
|
|
60
|
+
for (const variant of flattened) {
|
|
61
|
+
if (variant.kind === "unknown") return { kind: "unknown" };
|
|
62
|
+
const key = JSON.stringify(variant);
|
|
63
|
+
if (!unique.some((existing) => JSON.stringify(existing) === key)) unique.push(variant);
|
|
64
|
+
}
|
|
65
|
+
if (unique.length === 1) return unique[0];
|
|
66
|
+
if (unique.length > OBSERVED_OUTPUT_SHAPE_LIMITS.maxUnionVariants) return { kind: "unknown" };
|
|
67
|
+
return {
|
|
68
|
+
kind: "union",
|
|
69
|
+
variants: unique.sort((a, b) => a.kind.localeCompare(b.kind))
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
//#endregion
|
|
73
|
+
//#region src/observed-output-shapes/typescript.ts
|
|
74
|
+
function shapeToTypeScript(shape, typeName = "ObservedOutput", maxChars = OBSERVED_OUTPUT_SHAPE_LIMITS.maxTypeScriptChars) {
|
|
75
|
+
const typeScript = `type ${typeName} = ${shapeType(shape)};`;
|
|
76
|
+
if (typeScript.length <= maxChars) return {
|
|
77
|
+
typeScript,
|
|
78
|
+
truncated: hasTruncatedShape(shape)
|
|
79
|
+
};
|
|
80
|
+
return {
|
|
81
|
+
typeScript: `type ${typeName} = unknown;`,
|
|
82
|
+
truncated: true
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
function shapeType(shape) {
|
|
86
|
+
switch (shape.kind) {
|
|
87
|
+
case "null": return "null";
|
|
88
|
+
case "boolean": return "boolean";
|
|
89
|
+
case "number": return "number";
|
|
90
|
+
case "string": return "string";
|
|
91
|
+
case "unknown": return "unknown";
|
|
92
|
+
case "array": return `${shape.element ? wrapArrayElement(shapeType(shape.element)) : "unknown"}[]`;
|
|
93
|
+
case "object": return objectType(shape);
|
|
94
|
+
case "union": return unionType(shape.variants);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
function hasTruncatedShape(shape) {
|
|
98
|
+
if ("truncated" in shape && shape.truncated === true) return true;
|
|
99
|
+
if (shape.kind === "array") return shape.element ? hasTruncatedShape(shape.element) : false;
|
|
100
|
+
if (shape.kind === "object") return Object.values(shape.fields).some((field) => hasTruncatedShape(field.shape));
|
|
101
|
+
if (shape.kind === "union") return shape.variants.some((variant) => hasTruncatedShape(variant));
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
function objectType(shape) {
|
|
105
|
+
const entries = Object.entries(shape.fields);
|
|
106
|
+
if (entries.length === 0) return "Record<string, unknown>";
|
|
107
|
+
return `{ ${entries.map(([key, field]) => `${propertyName(key)}?: ${shapeType(field.shape)};`).join(" ")} }`;
|
|
108
|
+
}
|
|
109
|
+
function unionType(variants) {
|
|
110
|
+
const rendered = [...new Set(variants.map((variant) => shapeType(variant)))];
|
|
111
|
+
return rendered.length === 0 ? "unknown" : rendered.join(" | ");
|
|
112
|
+
}
|
|
113
|
+
function wrapArrayElement(value) {
|
|
114
|
+
return value.includes(" | ") ? `(${value})` : value;
|
|
115
|
+
}
|
|
116
|
+
function propertyName(key) {
|
|
117
|
+
return /^[A-Za-z_$][\w$]*$/u.test(key) ? key : JSON.stringify(key);
|
|
118
|
+
}
|
|
119
|
+
//#endregion
|
|
120
|
+
//#region src/observed-output-shapes/extract.ts
|
|
121
|
+
function observeOutputShape(input) {
|
|
122
|
+
const shape = extractJsonShape(input.value);
|
|
123
|
+
if (!shape) return void 0;
|
|
124
|
+
const merged = input.existing ? mergeJsonShapes(input.existing.jsonShape, shape) : shape;
|
|
125
|
+
const emitted = shapeToTypeScript(merged);
|
|
126
|
+
const observed = {
|
|
127
|
+
version: 1,
|
|
128
|
+
source: "observed",
|
|
129
|
+
observedAt: (input.now ?? /* @__PURE__ */ new Date()).toISOString(),
|
|
130
|
+
sampleCount: (input.existing?.sampleCount ?? 0) + 1,
|
|
131
|
+
typeScript: emitted.typeScript,
|
|
132
|
+
jsonShape: merged,
|
|
133
|
+
truncated: emitted.truncated || hasTruncatedShape(merged)
|
|
134
|
+
};
|
|
135
|
+
return storedBytes(observed) > OBSERVED_OUTPUT_SHAPE_LIMITS.maxStoredJsonBytes ? {
|
|
136
|
+
...observed,
|
|
137
|
+
typeScript: "type ObservedOutput = unknown;",
|
|
138
|
+
jsonShape: { kind: "unknown" },
|
|
139
|
+
truncated: true
|
|
140
|
+
} : observed;
|
|
141
|
+
}
|
|
142
|
+
function extractJsonShape(value) {
|
|
143
|
+
if (!isShapeableJsonRoot(value)) return void 0;
|
|
144
|
+
return shapeFor(value, 0);
|
|
145
|
+
}
|
|
146
|
+
function parseShapeableJsonText(value) {
|
|
147
|
+
if (!isPlainObject$1(value) || !Array.isArray(value.content) || value.content.length !== 1) return;
|
|
148
|
+
const [item] = value.content;
|
|
149
|
+
if (!isPlainObject$1(item) || item.type !== "text" || typeof item.text !== "string") return;
|
|
150
|
+
const text = item.text.trim();
|
|
151
|
+
if (!text || !text.startsWith("{") && !text.startsWith("[")) return void 0;
|
|
152
|
+
try {
|
|
153
|
+
const parsed = JSON.parse(text);
|
|
154
|
+
return isShapeableJsonRoot(parsed) ? parsed : void 0;
|
|
155
|
+
} catch {
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
function normalizedObservableValue(result) {
|
|
160
|
+
if (isPlainObject$1(result)) {
|
|
161
|
+
const structured = result.structuredContent;
|
|
162
|
+
if (structured !== void 0) {
|
|
163
|
+
if (isPlainObject$1(structured) && "caplets" in structured && "result" in structured) return isShapeableJsonRoot(structured.result) ? structured.result : void 0;
|
|
164
|
+
return isShapeableJsonRoot(structured) ? structured : void 0;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
return parseShapeableJsonText(result);
|
|
168
|
+
}
|
|
169
|
+
function shapeFor(value, depth) {
|
|
170
|
+
if (depth >= OBSERVED_OUTPUT_SHAPE_LIMITS.maxDepth) return { kind: "unknown" };
|
|
171
|
+
if (value === null) return { kind: "null" };
|
|
172
|
+
if (typeof value === "boolean") return { kind: "boolean" };
|
|
173
|
+
if (typeof value === "number") return { kind: "number" };
|
|
174
|
+
if (typeof value === "string") return { kind: "string" };
|
|
175
|
+
if (Array.isArray(value)) return arrayShape(value, depth);
|
|
176
|
+
if (isPlainObject$1(value)) return objectShape(value, depth);
|
|
177
|
+
return { kind: "unknown" };
|
|
178
|
+
}
|
|
179
|
+
function arrayShape(value, depth) {
|
|
180
|
+
const sampled = value.slice(0, OBSERVED_OUTPUT_SHAPE_LIMITS.maxArrayElements);
|
|
181
|
+
let element;
|
|
182
|
+
for (const item of sampled) {
|
|
183
|
+
const itemShape = shapeFor(item, depth + 1);
|
|
184
|
+
element = element ? mergeJsonShapes(element, itemShape) : itemShape;
|
|
185
|
+
}
|
|
186
|
+
return {
|
|
187
|
+
kind: "array",
|
|
188
|
+
...element ? { element } : {},
|
|
189
|
+
...value.length > sampled.length ? { truncated: true } : {}
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
function objectShape(value, depth) {
|
|
193
|
+
const keys = Object.keys(value).sort();
|
|
194
|
+
const selected = keys.slice(0, OBSERVED_OUTPUT_SHAPE_LIMITS.maxObjectFields);
|
|
195
|
+
const fields = {};
|
|
196
|
+
for (const key of selected) fields[key] = {
|
|
197
|
+
optional: true,
|
|
198
|
+
shape: shapeFor(value[key], depth + 1)
|
|
199
|
+
};
|
|
200
|
+
return {
|
|
201
|
+
kind: "object",
|
|
202
|
+
fields,
|
|
203
|
+
...keys.length > selected.length ? { truncated: true } : {}
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
function isShapeableJsonRoot(value) {
|
|
207
|
+
return Array.isArray(value) || isPlainObject$1(value);
|
|
208
|
+
}
|
|
209
|
+
function isPlainObject$1(value) {
|
|
210
|
+
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
211
|
+
}
|
|
212
|
+
function storedBytes(value) {
|
|
213
|
+
return new TextEncoder().encode(JSON.stringify(value)).byteLength;
|
|
214
|
+
}
|
|
215
|
+
//#endregion
|
|
216
|
+
//#region src/observed-output-shapes/schema.ts
|
|
217
|
+
function usefulOutputSchema(schema) {
|
|
218
|
+
if (!isPlainObject(schema)) return false;
|
|
219
|
+
if (Object.keys(schema).length === 0) return false;
|
|
220
|
+
if ("const" in schema || Array.isArray(schema.enum)) return true;
|
|
221
|
+
const type = schema.type;
|
|
222
|
+
if (Array.isArray(type)) return type.some((item) => usefulOutputSchema({
|
|
223
|
+
...schema,
|
|
224
|
+
type: item
|
|
225
|
+
}));
|
|
226
|
+
if (type === "object" || isPlainObject(schema.properties)) {
|
|
227
|
+
if (isPlainObject(schema.properties) && Object.keys(schema.properties).length > 0) return true;
|
|
228
|
+
if (schema.additionalProperties === false) return true;
|
|
229
|
+
if (isPlainObject(schema.additionalProperties)) return true;
|
|
230
|
+
return false;
|
|
231
|
+
}
|
|
232
|
+
if (type === "array") return usefulOutputSchema(schema.items);
|
|
233
|
+
if (typeof type === "string") return true;
|
|
234
|
+
if (Array.isArray(schema.oneOf) || Array.isArray(schema.anyOf) || Array.isArray(schema.allOf)) return true;
|
|
235
|
+
return false;
|
|
236
|
+
}
|
|
237
|
+
function isPlainObject(value) {
|
|
238
|
+
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
239
|
+
}
|
|
240
|
+
//#endregion
|
|
241
|
+
export { OBSERVED_OUTPUT_SHAPE_LIMITS, OBSERVED_OUTPUT_SHAPE_VERSION, extractJsonShape, hasTruncatedShape, mergeJsonShapes, normalizedObservableValue, observeOutputShape, parseShapeableJsonText, shapeToTypeScript, shapeType, usefulOutputSchema };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function usefulOutputSchema(schema: unknown): boolean;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import type { JsonValue } from "../code-mode/types";
|
|
2
|
+
export declare const OBSERVED_OUTPUT_SHAPE_VERSION = 1;
|
|
3
|
+
export declare const OBSERVED_OUTPUT_SHAPE_LIMITS: {
|
|
4
|
+
readonly maxDepth: 6;
|
|
5
|
+
readonly maxObjectFields: 40;
|
|
6
|
+
readonly maxArrayElements: 20;
|
|
7
|
+
readonly maxUnionVariants: 4;
|
|
8
|
+
readonly maxTypeScriptChars: 4000;
|
|
9
|
+
readonly maxStoredJsonBytes: 16000;
|
|
10
|
+
readonly ttlMs: number;
|
|
11
|
+
readonly maxLocalEntries: 2000;
|
|
12
|
+
};
|
|
13
|
+
export type JsonShape = {
|
|
14
|
+
kind: "null";
|
|
15
|
+
} | {
|
|
16
|
+
kind: "boolean";
|
|
17
|
+
} | {
|
|
18
|
+
kind: "number";
|
|
19
|
+
} | {
|
|
20
|
+
kind: "string";
|
|
21
|
+
} | {
|
|
22
|
+
kind: "unknown";
|
|
23
|
+
} | {
|
|
24
|
+
kind: "array";
|
|
25
|
+
element?: JsonShape;
|
|
26
|
+
truncated?: boolean;
|
|
27
|
+
} | {
|
|
28
|
+
kind: "object";
|
|
29
|
+
fields: Record<string, {
|
|
30
|
+
optional: boolean;
|
|
31
|
+
shape: JsonShape;
|
|
32
|
+
}>;
|
|
33
|
+
truncated?: boolean;
|
|
34
|
+
} | {
|
|
35
|
+
kind: "union";
|
|
36
|
+
variants: JsonShape[];
|
|
37
|
+
};
|
|
38
|
+
export type ObservedOutputShape = {
|
|
39
|
+
version: 1;
|
|
40
|
+
source: "observed";
|
|
41
|
+
observedAt: string;
|
|
42
|
+
sampleCount: number;
|
|
43
|
+
typeScript: string;
|
|
44
|
+
jsonShape: JsonShape;
|
|
45
|
+
truncated: boolean;
|
|
46
|
+
};
|
|
47
|
+
export type ObservedOutputShapeKey = {
|
|
48
|
+
scope: "local" | "self_hosted" | "cloud";
|
|
49
|
+
workspaceId?: string | undefined;
|
|
50
|
+
projectFingerprint?: string | undefined;
|
|
51
|
+
capletId: string;
|
|
52
|
+
backendKind: string;
|
|
53
|
+
backendFingerprint: string;
|
|
54
|
+
toolName: string;
|
|
55
|
+
toolDescriptorHash?: string | undefined;
|
|
56
|
+
outputSchemaHash?: string | undefined;
|
|
57
|
+
resultVersion: 1;
|
|
58
|
+
};
|
|
59
|
+
export type ObservedOutputShapePruneResult = {
|
|
60
|
+
removed: number;
|
|
61
|
+
remaining: number;
|
|
62
|
+
};
|
|
63
|
+
export type ObservedOutputShapeStoreHealth = {
|
|
64
|
+
path?: string | undefined;
|
|
65
|
+
readable: boolean;
|
|
66
|
+
writable: boolean;
|
|
67
|
+
entryCount?: number | undefined;
|
|
68
|
+
prune?: ObservedOutputShapePruneResult | undefined;
|
|
69
|
+
error?: string | undefined;
|
|
70
|
+
};
|
|
71
|
+
export interface ObservedOutputShapeStore {
|
|
72
|
+
read(key: ObservedOutputShapeKey): Promise<ObservedOutputShape | undefined>;
|
|
73
|
+
write(key: ObservedOutputShapeKey, shape: ObservedOutputShape): Promise<void>;
|
|
74
|
+
prune?(now?: Date): Promise<ObservedOutputShapePruneResult>;
|
|
75
|
+
health?(): Promise<ObservedOutputShapeStoreHealth>;
|
|
76
|
+
}
|
|
77
|
+
export type ExtractObservedOutputShapeInput = {
|
|
78
|
+
value: unknown;
|
|
79
|
+
now?: Date | undefined;
|
|
80
|
+
existing?: ObservedOutputShape | undefined;
|
|
81
|
+
};
|
|
82
|
+
export type ExtractedJsonValue = Extract<JsonValue, unknown[] | {
|
|
83
|
+
[key: string]: JsonValue;
|
|
84
|
+
}>;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type JsonShape } from "./types";
|
|
2
|
+
export declare function shapeToTypeScript(shape: JsonShape, typeName?: string, maxChars?: number): {
|
|
3
|
+
typeScript: string;
|
|
4
|
+
truncated: boolean;
|
|
5
|
+
};
|
|
6
|
+
export declare function shapeType(shape: JsonShape): string;
|
|
7
|
+
export declare function hasTruncatedShape(shape: JsonShape): boolean;
|