@agen-ai/agent-protocol 0.4.2 → 0.4.4
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 +151 -21
- package/dist/capabilities/types.d.ts +3 -1
- package/dist/events/types.d.ts +1 -1
- package/dist/foundation/types.d.ts +2 -1
- package/dist/foundation/types.js +1 -1
- package/dist/jsonSchema/generated.d.ts +13637 -9890
- package/dist/jsonSchema/generated.js +3025 -644
- package/dist/public/index.d.ts +1 -0
- package/dist/public/index.js +1 -0
- package/dist/public/structuredOutput.d.ts +2 -0
- package/dist/public/structuredOutput.js +1 -0
- package/dist/sessions/types.d.ts +2 -0
- package/dist/structuredOutput/boundedJson.d.ts +13 -0
- package/dist/structuredOutput/boundedJson.js +143 -0
- package/dist/structuredOutput/constants.d.ts +24 -0
- package/dist/structuredOutput/constants.js +57 -0
- package/dist/structuredOutput/definition.d.ts +9 -0
- package/dist/structuredOutput/definition.js +15 -0
- package/dist/structuredOutput/index.d.ts +9 -0
- package/dist/structuredOutput/index.js +12 -0
- package/dist/structuredOutput/issues.d.ts +8 -0
- package/dist/structuredOutput/issues.js +76 -0
- package/dist/structuredOutput/parsers.d.ts +10 -0
- package/dist/structuredOutput/parsers.js +74 -0
- package/dist/structuredOutput/schemaAdmission.d.ts +9 -0
- package/dist/structuredOutput/schemaAdmission.js +247 -0
- package/dist/structuredOutput/types.d.ts +75 -0
- package/dist/structuredOutput/types.js +0 -0
- package/dist/structuredOutput/values.d.ts +5 -0
- package/dist/structuredOutput/values.js +89 -0
- package/dist/turns/types.d.ts +18 -5
- package/dist/zod/capabilities.d.ts +3 -2
- package/dist/zod/capabilities.js +2 -0
- package/dist/zod/events.d.ts +24 -33
- package/dist/zod/events.js +94 -94
- package/dist/zod/foundation.d.ts +1 -0
- package/dist/zod/foundation.js +3 -0
- package/dist/zod/index.d.ts +2 -0
- package/dist/zod/index.js +25 -1
- package/dist/zod/operations.d.ts +2 -2
- package/dist/zod/outputDefinition.d.ts +4 -0
- package/dist/zod/outputDefinition.js +22 -0
- package/dist/zod/outputSchema.d.ts +4 -0
- package/dist/zod/outputSchema.js +177 -0
- package/dist/zod/sessions.d.ts +14 -0
- package/dist/zod/sessions.js +26 -3
- package/dist/zod/structuredOutput.d.ts +14 -0
- package/dist/zod/structuredOutput.js +209 -0
- package/dist/zod/turns.d.ts +19 -5
- package/dist/zod/turns.js +63 -24
- package/dist/zod/typeEquality.generated.d.ts +16 -2
- package/package.json +6 -2
package/dist/public/index.d.ts
CHANGED
package/dist/public/index.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "../structuredOutput/index.js";
|
package/dist/sessions/types.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { AgentConfigurationRevisionId, AgentProviderConversationId, AgentProviderHistoryAnchor, AgentSessionId, AgentTurnId } from '../foundation/index.js';
|
|
2
2
|
import type { AgentConfigurationValue } from '../configuration/index.js';
|
|
3
|
+
import type { AgentStructuredOutputRequest } from '../structuredOutput/types.js';
|
|
3
4
|
export interface AgentSessionBinding {
|
|
4
5
|
readonly conversationId: AgentProviderConversationId;
|
|
5
6
|
readonly historyAnchor?: AgentProviderHistoryAnchor;
|
|
@@ -20,6 +21,7 @@ export type AgentSessionConfiguration = Readonly<{
|
|
|
20
21
|
}>;
|
|
21
22
|
export interface AgentSessionCreateInput {
|
|
22
23
|
readonly operation: 'create';
|
|
24
|
+
readonly output?: AgentStructuredOutputRequest;
|
|
23
25
|
readonly sessionId: AgentSessionId;
|
|
24
26
|
readonly configuration: AgentSessionConfiguration;
|
|
25
27
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { AgentJsonObject, AgentJsonValue, AgentProtocolParseResult } from '../foundation/types.js';
|
|
2
|
+
export interface StructuredOutputJsonBounds {
|
|
3
|
+
readonly maxBytes: number;
|
|
4
|
+
readonly maxDepth: number;
|
|
5
|
+
readonly maxNodes: number;
|
|
6
|
+
readonly maxCollectionLength: number;
|
|
7
|
+
}
|
|
8
|
+
export declare function isJsonObject(value: AgentJsonValue): value is AgentJsonObject;
|
|
9
|
+
export declare function codePointLength(value: string): number;
|
|
10
|
+
export declare function isOutputPropertyName(value: string): boolean;
|
|
11
|
+
export declare function serializedStringBytes(value: string, stopAfter: number): number;
|
|
12
|
+
export declare function snapshotStructuredOutputJson(input: unknown, bounds: StructuredOutputJsonBounds): AgentProtocolParseResult<AgentJsonValue>;
|
|
13
|
+
//# sourceMappingURL=boundedJson.d.ts.map
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { AGENT_OUTPUT_SCHEMA_PROPERTY_NAME_MAX_LENGTH } from "./constants.js";
|
|
2
|
+
import { StructuredOutputIssues } from "./issues.js";
|
|
3
|
+
function isJsonObject(value) {
|
|
4
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
5
|
+
}
|
|
6
|
+
function codePointLength(value) {
|
|
7
|
+
let length = 0;
|
|
8
|
+
for (const _point of value) length += 1;
|
|
9
|
+
return length;
|
|
10
|
+
}
|
|
11
|
+
function isOutputPropertyName(value) {
|
|
12
|
+
return value.length > 0 && value.length <= 2 * AGENT_OUTPUT_SCHEMA_PROPERTY_NAME_MAX_LENGTH && value !== "__proto__" && value !== "constructor" && value !== "prototype" && codePointLength(value) <= AGENT_OUTPUT_SCHEMA_PROPERTY_NAME_MAX_LENGTH;
|
|
13
|
+
}
|
|
14
|
+
function serializedStringBytes(value, stopAfter) {
|
|
15
|
+
let bytes = 2;
|
|
16
|
+
for (let index = 0; index < value.length; index += 1) {
|
|
17
|
+
const unit = value.charCodeAt(index);
|
|
18
|
+
if (unit === 34 || unit === 92) bytes += 2;
|
|
19
|
+
else if (unit <= 31) bytes += [8, 9, 10, 12, 13].includes(unit) ? 2 : 6;
|
|
20
|
+
else if (unit <= 127) bytes += 1;
|
|
21
|
+
else if (unit <= 2047) bytes += 2;
|
|
22
|
+
else if (unit >= 55296 && unit <= 56319) {
|
|
23
|
+
const next = value.charCodeAt(index + 1);
|
|
24
|
+
if (next >= 56320 && next <= 57343) {
|
|
25
|
+
bytes += 4;
|
|
26
|
+
index += 1;
|
|
27
|
+
} else bytes += 6;
|
|
28
|
+
} else if (unit >= 56320 && unit <= 57343) bytes += 6;
|
|
29
|
+
else bytes += 3;
|
|
30
|
+
if (bytes > stopAfter) break;
|
|
31
|
+
}
|
|
32
|
+
return bytes;
|
|
33
|
+
}
|
|
34
|
+
function snapshotStructuredOutputJson(input, bounds) {
|
|
35
|
+
const issues = new StructuredOutputIssues();
|
|
36
|
+
const active = /* @__PURE__ */ new WeakSet();
|
|
37
|
+
let bytes = 0;
|
|
38
|
+
let nodes = 0;
|
|
39
|
+
function fail(code, message, path) {
|
|
40
|
+
issues.add(code, message, path);
|
|
41
|
+
return void 0;
|
|
42
|
+
}
|
|
43
|
+
function charge(amount, path) {
|
|
44
|
+
bytes += amount;
|
|
45
|
+
if (bytes <= bounds.maxBytes) return true;
|
|
46
|
+
fail("output_limit_exceeded", "JSON data exceeds the serialized UTF-8 byte limit.", path);
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
function copy(value, depth, path) {
|
|
50
|
+
nodes += 1;
|
|
51
|
+
if (nodes > bounds.maxNodes || depth > bounds.maxDepth) {
|
|
52
|
+
return fail("output_limit_exceeded", "JSON data exceeds the node or depth limit.", path);
|
|
53
|
+
}
|
|
54
|
+
if (value === null || typeof value === "boolean") {
|
|
55
|
+
return charge(value === null ? 4 : value ? 4 : 5, path) ? value : void 0;
|
|
56
|
+
}
|
|
57
|
+
if (typeof value === "string") {
|
|
58
|
+
return charge(serializedStringBytes(value, bounds.maxBytes - bytes), path) ? value : void 0;
|
|
59
|
+
}
|
|
60
|
+
if (typeof value === "number") {
|
|
61
|
+
if (!Number.isFinite(value)) return fail("invalid_json_data", "JSON numbers must be finite.", path);
|
|
62
|
+
return charge(JSON.stringify(value).length, path) ? value : void 0;
|
|
63
|
+
}
|
|
64
|
+
if (typeof value !== "object") return fail("invalid_json_data", "Only plain JSON data is accepted.", path);
|
|
65
|
+
if (active.has(value)) return fail("invalid_json_data", "JSON data must not contain cycles.", path);
|
|
66
|
+
const array = Array.isArray(value);
|
|
67
|
+
let keys;
|
|
68
|
+
let length = 0;
|
|
69
|
+
try {
|
|
70
|
+
const prototype = Object.getPrototypeOf(value);
|
|
71
|
+
if (prototype !== (array ? Array.prototype : Object.prototype) && !(prototype === null && !array)) {
|
|
72
|
+
return fail("invalid_json_data", "JSON data must use plain object and array prototypes.", path);
|
|
73
|
+
}
|
|
74
|
+
if (array) {
|
|
75
|
+
const descriptor = Object.getOwnPropertyDescriptor(value, "length");
|
|
76
|
+
const arrayLength = descriptor?.value;
|
|
77
|
+
if (!descriptor || !("value" in descriptor) || typeof arrayLength !== "number" || !Number.isSafeInteger(arrayLength) || arrayLength < 0 || arrayLength > bounds.maxCollectionLength) {
|
|
78
|
+
return fail("output_limit_exceeded", "JSON arrays exceed the collection limit.", path);
|
|
79
|
+
}
|
|
80
|
+
length = arrayLength;
|
|
81
|
+
}
|
|
82
|
+
keys = Reflect.ownKeys(value);
|
|
83
|
+
} catch {
|
|
84
|
+
return fail("invalid_json_data", "JSON data properties cannot be inspected safely.", path);
|
|
85
|
+
}
|
|
86
|
+
if (keys.length > bounds.maxCollectionLength + (array ? 1 : 0)) {
|
|
87
|
+
return fail("output_limit_exceeded", "JSON collections exceed the entry limit.", path);
|
|
88
|
+
}
|
|
89
|
+
if (array && keys.length !== length + 1) return fail("invalid_json_data", "JSON arrays must be dense and have no extra properties.", path);
|
|
90
|
+
const entries = [];
|
|
91
|
+
for (const key of keys) {
|
|
92
|
+
if (array && key === "length") continue;
|
|
93
|
+
if (typeof key !== "string" || !array && !isOutputPropertyName(key)) {
|
|
94
|
+
return fail("invalid_json_data", "JSON object property names must be bounded and safe.", path);
|
|
95
|
+
}
|
|
96
|
+
if (array && (!/^(?:0|[1-9][0-9]*)$/u.test(key) || Number(key) >= length)) {
|
|
97
|
+
return fail("invalid_json_data", "JSON arrays must have only indexed entries.", path);
|
|
98
|
+
}
|
|
99
|
+
let descriptor;
|
|
100
|
+
try {
|
|
101
|
+
descriptor = Object.getOwnPropertyDescriptor(value, key);
|
|
102
|
+
} catch {
|
|
103
|
+
return fail("invalid_json_data", "JSON data properties cannot be inspected safely.", path);
|
|
104
|
+
}
|
|
105
|
+
if (!descriptor || !("value" in descriptor) || !descriptor.enumerable) {
|
|
106
|
+
return fail("invalid_json_data", "JSON data must contain only enumerable data properties.", path);
|
|
107
|
+
}
|
|
108
|
+
const child = descriptor.value;
|
|
109
|
+
entries.push([key, child]);
|
|
110
|
+
}
|
|
111
|
+
if (!charge(2 + Math.max(0, entries.length - 1), path)) return void 0;
|
|
112
|
+
active.add(value);
|
|
113
|
+
if (array) {
|
|
114
|
+
const result2 = [];
|
|
115
|
+
for (const [key, child] of entries) {
|
|
116
|
+
const copied = copy(child, depth + 1, [...path, Number(key)]);
|
|
117
|
+
if (copied === void 0) return void 0;
|
|
118
|
+
result2.push(copied);
|
|
119
|
+
}
|
|
120
|
+
active.delete(value);
|
|
121
|
+
return result2;
|
|
122
|
+
}
|
|
123
|
+
const result = {};
|
|
124
|
+
for (const [key, child] of entries) {
|
|
125
|
+
const childPath = [...path, key];
|
|
126
|
+
if (!charge(serializedStringBytes(key, bounds.maxBytes - bytes) + 1, childPath)) return void 0;
|
|
127
|
+
const copied = copy(child, depth + 1, childPath);
|
|
128
|
+
if (copied === void 0) return void 0;
|
|
129
|
+
result[key] = copied;
|
|
130
|
+
}
|
|
131
|
+
active.delete(value);
|
|
132
|
+
return result;
|
|
133
|
+
}
|
|
134
|
+
const data = copy(input, 1, []);
|
|
135
|
+
return data === void 0 ? { success: false, issues: issues.issues } : { success: true, data };
|
|
136
|
+
}
|
|
137
|
+
export {
|
|
138
|
+
codePointLength,
|
|
139
|
+
isJsonObject,
|
|
140
|
+
isOutputPropertyName,
|
|
141
|
+
serializedStringBytes,
|
|
142
|
+
snapshotStructuredOutputJson
|
|
143
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export declare const AGENT_OUTPUT_SCHEMA_PROFILE: "agenai.output-schema.v1";
|
|
2
|
+
export declare const AGENT_OUTPUT_SCHEMA_DIALECT: "https://json-schema.org/draft/2020-12/schema";
|
|
3
|
+
export declare const AGENT_OUTPUT_SCHEMA_BYTES_LIMIT = 16384;
|
|
4
|
+
export declare const AGENT_OUTPUT_SCHEMA_NODES_LIMIT = 256;
|
|
5
|
+
export declare const AGENT_OUTPUT_SCHEMA_DEPTH_LIMIT = 8;
|
|
6
|
+
export declare const AGENT_OUTPUT_SCHEMA_PROPERTIES_LIMIT = 100;
|
|
7
|
+
export declare const AGENT_OUTPUT_SCHEMA_PROPERTY_NAME_MAX_LENGTH = 128;
|
|
8
|
+
export declare const AGENT_OUTPUT_SCHEMA_DESCRIPTION_MAX_LENGTH = 2000;
|
|
9
|
+
export declare const AGENT_OUTPUT_SCHEMA_ENUM_VALUES_LIMIT = 100;
|
|
10
|
+
export declare const AGENT_OUTPUT_SCHEMA_LENGTH_BOUND_LIMIT = 16384;
|
|
11
|
+
export declare const AGENT_OUTPUT_VALUE_BYTES_LIMIT = 16384;
|
|
12
|
+
export declare const AGENT_OUTPUT_VALUE_NODES_LIMIT = 1024;
|
|
13
|
+
export declare const AGENT_OUTPUT_VALUE_DEPTH_LIMIT = 16;
|
|
14
|
+
export declare const AGENT_OUTPUT_VALUE_COLLECTION_LIMIT = 100;
|
|
15
|
+
export declare const AGENT_OUTPUT_RAW_JSON_BYTES_LIMIT = 65536;
|
|
16
|
+
export declare const AGENT_STRUCTURED_OUTPUT_ISSUES_LIMIT = 8;
|
|
17
|
+
export declare const AGENT_STRUCTURED_OUTPUT_ISSUES_BYTES_LIMIT = 4096;
|
|
18
|
+
export declare const AGENT_STRUCTURED_OUTPUT_ISSUE_CODE_MAX_LENGTH = 64;
|
|
19
|
+
export declare const AGENT_STRUCTURED_OUTPUT_ISSUE_MESSAGE_MAX_LENGTH = 256;
|
|
20
|
+
export declare const AGENT_STRUCTURED_OUTPUT_ISSUE_PATH_SEGMENTS_LIMIT = 16;
|
|
21
|
+
export declare const AGENT_STRUCTURED_OUTPUT_ISSUE_PATH_BYTES_LIMIT = 1024;
|
|
22
|
+
export declare const AGENT_STRUCTURED_OUTPUT_TURN_REQUEST_BYTES_LIMIT = 1085440;
|
|
23
|
+
export declare const AGENT_STRUCTURED_OUTPUT_UNAVAILABLE_REASONS: readonly ["refused", "incomplete", "missing_output", "invalid_json", "schema_mismatch", "output_limit_exceeded", "native_retries_exhausted", "provider_error"];
|
|
24
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
const AGENT_OUTPUT_SCHEMA_PROFILE = "agenai.output-schema.v1";
|
|
2
|
+
const AGENT_OUTPUT_SCHEMA_DIALECT = "https://json-schema.org/draft/2020-12/schema";
|
|
3
|
+
const AGENT_OUTPUT_SCHEMA_BYTES_LIMIT = 16384;
|
|
4
|
+
const AGENT_OUTPUT_SCHEMA_NODES_LIMIT = 256;
|
|
5
|
+
const AGENT_OUTPUT_SCHEMA_DEPTH_LIMIT = 8;
|
|
6
|
+
const AGENT_OUTPUT_SCHEMA_PROPERTIES_LIMIT = 100;
|
|
7
|
+
const AGENT_OUTPUT_SCHEMA_PROPERTY_NAME_MAX_LENGTH = 128;
|
|
8
|
+
const AGENT_OUTPUT_SCHEMA_DESCRIPTION_MAX_LENGTH = 2e3;
|
|
9
|
+
const AGENT_OUTPUT_SCHEMA_ENUM_VALUES_LIMIT = 100;
|
|
10
|
+
const AGENT_OUTPUT_SCHEMA_LENGTH_BOUND_LIMIT = 16384;
|
|
11
|
+
const AGENT_OUTPUT_VALUE_BYTES_LIMIT = 16384;
|
|
12
|
+
const AGENT_OUTPUT_VALUE_NODES_LIMIT = 1024;
|
|
13
|
+
const AGENT_OUTPUT_VALUE_DEPTH_LIMIT = 16;
|
|
14
|
+
const AGENT_OUTPUT_VALUE_COLLECTION_LIMIT = 100;
|
|
15
|
+
const AGENT_OUTPUT_RAW_JSON_BYTES_LIMIT = 65536;
|
|
16
|
+
const AGENT_STRUCTURED_OUTPUT_ISSUES_LIMIT = 8;
|
|
17
|
+
const AGENT_STRUCTURED_OUTPUT_ISSUES_BYTES_LIMIT = 4096;
|
|
18
|
+
const AGENT_STRUCTURED_OUTPUT_ISSUE_CODE_MAX_LENGTH = 64;
|
|
19
|
+
const AGENT_STRUCTURED_OUTPUT_ISSUE_MESSAGE_MAX_LENGTH = 256;
|
|
20
|
+
const AGENT_STRUCTURED_OUTPUT_ISSUE_PATH_SEGMENTS_LIMIT = 16;
|
|
21
|
+
const AGENT_STRUCTURED_OUTPUT_ISSUE_PATH_BYTES_LIMIT = 1024;
|
|
22
|
+
const AGENT_STRUCTURED_OUTPUT_TURN_REQUEST_BYTES_LIMIT = 1085440;
|
|
23
|
+
const AGENT_STRUCTURED_OUTPUT_UNAVAILABLE_REASONS = [
|
|
24
|
+
"refused",
|
|
25
|
+
"incomplete",
|
|
26
|
+
"missing_output",
|
|
27
|
+
"invalid_json",
|
|
28
|
+
"schema_mismatch",
|
|
29
|
+
"output_limit_exceeded",
|
|
30
|
+
"native_retries_exhausted",
|
|
31
|
+
"provider_error"
|
|
32
|
+
];
|
|
33
|
+
export {
|
|
34
|
+
AGENT_OUTPUT_RAW_JSON_BYTES_LIMIT,
|
|
35
|
+
AGENT_OUTPUT_SCHEMA_BYTES_LIMIT,
|
|
36
|
+
AGENT_OUTPUT_SCHEMA_DEPTH_LIMIT,
|
|
37
|
+
AGENT_OUTPUT_SCHEMA_DESCRIPTION_MAX_LENGTH,
|
|
38
|
+
AGENT_OUTPUT_SCHEMA_DIALECT,
|
|
39
|
+
AGENT_OUTPUT_SCHEMA_ENUM_VALUES_LIMIT,
|
|
40
|
+
AGENT_OUTPUT_SCHEMA_LENGTH_BOUND_LIMIT,
|
|
41
|
+
AGENT_OUTPUT_SCHEMA_NODES_LIMIT,
|
|
42
|
+
AGENT_OUTPUT_SCHEMA_PROFILE,
|
|
43
|
+
AGENT_OUTPUT_SCHEMA_PROPERTIES_LIMIT,
|
|
44
|
+
AGENT_OUTPUT_SCHEMA_PROPERTY_NAME_MAX_LENGTH,
|
|
45
|
+
AGENT_OUTPUT_VALUE_BYTES_LIMIT,
|
|
46
|
+
AGENT_OUTPUT_VALUE_COLLECTION_LIMIT,
|
|
47
|
+
AGENT_OUTPUT_VALUE_DEPTH_LIMIT,
|
|
48
|
+
AGENT_OUTPUT_VALUE_NODES_LIMIT,
|
|
49
|
+
AGENT_STRUCTURED_OUTPUT_ISSUES_BYTES_LIMIT,
|
|
50
|
+
AGENT_STRUCTURED_OUTPUT_ISSUES_LIMIT,
|
|
51
|
+
AGENT_STRUCTURED_OUTPUT_ISSUE_CODE_MAX_LENGTH,
|
|
52
|
+
AGENT_STRUCTURED_OUTPUT_ISSUE_MESSAGE_MAX_LENGTH,
|
|
53
|
+
AGENT_STRUCTURED_OUTPUT_ISSUE_PATH_BYTES_LIMIT,
|
|
54
|
+
AGENT_STRUCTURED_OUTPUT_ISSUE_PATH_SEGMENTS_LIMIT,
|
|
55
|
+
AGENT_STRUCTURED_OUTPUT_TURN_REQUEST_BYTES_LIMIT,
|
|
56
|
+
AGENT_STRUCTURED_OUTPUT_UNAVAILABLE_REASONS
|
|
57
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { AgentJsonObject, AgentProtocolParseResult } from '../foundation/types.js';
|
|
2
|
+
import type { AgentOutputSchema } from './types.js';
|
|
3
|
+
export interface AgentOutputDefinition<T> {
|
|
4
|
+
readonly schema: AgentOutputSchema;
|
|
5
|
+
readonly decode: (value: AgentJsonObject) => AgentProtocolParseResult<T>;
|
|
6
|
+
}
|
|
7
|
+
export declare function createAgentOutputDefinition(schema: AgentOutputSchema): AgentOutputDefinition<AgentJsonObject>;
|
|
8
|
+
export declare function createAgentOutputDefinition<T>(schema: AgentOutputSchema, decode: (value: AgentJsonObject) => AgentProtocolParseResult<T>): AgentOutputDefinition<T>;
|
|
9
|
+
//# sourceMappingURL=definition.d.ts.map
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { parseAgentOutputSchema } from "./parsers.js";
|
|
2
|
+
function createAgentOutputDefinition(schema, decode) {
|
|
3
|
+
if (decode !== void 0 && typeof decode !== "function") {
|
|
4
|
+
throw new TypeError("An output definition decoder must be a function.");
|
|
5
|
+
}
|
|
6
|
+
const ownedSchema = parseAgentOutputSchema(schema);
|
|
7
|
+
if (decode !== void 0) return Object.freeze({ schema: ownedSchema, decode });
|
|
8
|
+
return Object.freeze({
|
|
9
|
+
schema: ownedSchema,
|
|
10
|
+
decode: (value) => ({ success: true, data: value })
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
export {
|
|
14
|
+
createAgentOutputDefinition
|
|
15
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from './constants.js';
|
|
2
|
+
export type * from './types.js';
|
|
3
|
+
export { parseAgentOutputSchema, safeParseAgentOutputSchema } from './parsers.js';
|
|
4
|
+
export type { AgentOutputLimits } from './parsers.js';
|
|
5
|
+
export { validateAgentOutputValue } from './values.js';
|
|
6
|
+
export { createAgentOutputDefinition } from './definition.js';
|
|
7
|
+
export type { AgentOutputDefinition } from './definition.js';
|
|
8
|
+
export { normalizeAgentStructuredOutputIssues } from './issues.js';
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export * from "./constants.js";
|
|
2
|
+
import { parseAgentOutputSchema, safeParseAgentOutputSchema } from "./parsers.js";
|
|
3
|
+
import { validateAgentOutputValue } from "./values.js";
|
|
4
|
+
import { createAgentOutputDefinition } from "./definition.js";
|
|
5
|
+
import { normalizeAgentStructuredOutputIssues } from "./issues.js";
|
|
6
|
+
export {
|
|
7
|
+
createAgentOutputDefinition,
|
|
8
|
+
normalizeAgentStructuredOutputIssues,
|
|
9
|
+
parseAgentOutputSchema,
|
|
10
|
+
safeParseAgentOutputSchema,
|
|
11
|
+
validateAgentOutputValue
|
|
12
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ValidationIssue, ValidationPathSegment } from '../foundation/types.js';
|
|
2
|
+
export declare class StructuredOutputIssues {
|
|
3
|
+
readonly issues: ValidationIssue[];
|
|
4
|
+
get full(): boolean;
|
|
5
|
+
add(code: string, message: string, inputPath?: readonly ValidationPathSegment[]): void;
|
|
6
|
+
}
|
|
7
|
+
export declare function normalizeAgentStructuredOutputIssues(input: readonly ValidationIssue[]): readonly ValidationIssue[];
|
|
8
|
+
//# sourceMappingURL=issues.d.ts.map
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AGENT_STRUCTURED_OUTPUT_ISSUE_CODE_MAX_LENGTH,
|
|
3
|
+
AGENT_STRUCTURED_OUTPUT_ISSUE_MESSAGE_MAX_LENGTH,
|
|
4
|
+
AGENT_STRUCTURED_OUTPUT_ISSUE_PATH_BYTES_LIMIT,
|
|
5
|
+
AGENT_STRUCTURED_OUTPUT_ISSUE_PATH_SEGMENTS_LIMIT,
|
|
6
|
+
AGENT_STRUCTURED_OUTPUT_ISSUES_BYTES_LIMIT,
|
|
7
|
+
AGENT_STRUCTURED_OUTPUT_ISSUES_LIMIT
|
|
8
|
+
} from "./constants.js";
|
|
9
|
+
const encoder = new TextEncoder();
|
|
10
|
+
function boundedText(value, maxLength) {
|
|
11
|
+
let result = "";
|
|
12
|
+
let length = 0;
|
|
13
|
+
for (const point of value) {
|
|
14
|
+
if (length === maxLength) break;
|
|
15
|
+
result += point;
|
|
16
|
+
length += 1;
|
|
17
|
+
}
|
|
18
|
+
return result;
|
|
19
|
+
}
|
|
20
|
+
class StructuredOutputIssues {
|
|
21
|
+
issues = [];
|
|
22
|
+
get full() {
|
|
23
|
+
return this.issues.length >= AGENT_STRUCTURED_OUTPUT_ISSUES_LIMIT;
|
|
24
|
+
}
|
|
25
|
+
add(code, message, inputPath = []) {
|
|
26
|
+
if (this.full) return;
|
|
27
|
+
const path = [];
|
|
28
|
+
for (const segment of inputPath) {
|
|
29
|
+
if (path.length === AGENT_STRUCTURED_OUTPUT_ISSUE_PATH_SEGMENTS_LIMIT) break;
|
|
30
|
+
if (typeof segment === "string" && segment.length > AGENT_STRUCTURED_OUTPUT_ISSUE_PATH_BYTES_LIMIT || typeof segment === "number" && !Number.isFinite(segment)) break;
|
|
31
|
+
const candidate = [...path, segment];
|
|
32
|
+
if (encoder.encode(JSON.stringify(candidate)).byteLength > AGENT_STRUCTURED_OUTPUT_ISSUE_PATH_BYTES_LIMIT) break;
|
|
33
|
+
path.push(segment);
|
|
34
|
+
}
|
|
35
|
+
const issue = {
|
|
36
|
+
code: boundedText(code, AGENT_STRUCTURED_OUTPUT_ISSUE_CODE_MAX_LENGTH),
|
|
37
|
+
path,
|
|
38
|
+
message: boundedText(message, AGENT_STRUCTURED_OUTPUT_ISSUE_MESSAGE_MAX_LENGTH)
|
|
39
|
+
};
|
|
40
|
+
if (encoder.encode(JSON.stringify([...this.issues, issue])).byteLength <= AGENT_STRUCTURED_OUTPUT_ISSUES_BYTES_LIMIT) {
|
|
41
|
+
this.issues.push(issue);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
function ownData(input, key) {
|
|
46
|
+
const descriptor = Object.getOwnPropertyDescriptor(input, key);
|
|
47
|
+
return descriptor && "value" in descriptor ? descriptor.value : void 0;
|
|
48
|
+
}
|
|
49
|
+
function normalizeAgentStructuredOutputIssues(input) {
|
|
50
|
+
const normalized = new StructuredOutputIssues();
|
|
51
|
+
if (!Array.isArray(input)) return Object.freeze([]);
|
|
52
|
+
const length = ownData(input, "length");
|
|
53
|
+
if (typeof length !== "number") return Object.freeze([]);
|
|
54
|
+
for (let index = 0; index < Math.min(length, AGENT_STRUCTURED_OUTPUT_ISSUES_LIMIT); index += 1) {
|
|
55
|
+
const issue = ownData(input, index);
|
|
56
|
+
if (issue === null || typeof issue !== "object") continue;
|
|
57
|
+
const code = ownData(issue, "code");
|
|
58
|
+
const message = ownData(issue, "message");
|
|
59
|
+
const sourcePath = ownData(issue, "path");
|
|
60
|
+
if (typeof code !== "string" || typeof message !== "string" || !Array.isArray(sourcePath)) continue;
|
|
61
|
+
const pathLength = ownData(sourcePath, "length");
|
|
62
|
+
if (typeof pathLength !== "number") continue;
|
|
63
|
+
const path = [];
|
|
64
|
+
for (let offset = 0; offset < Math.min(pathLength, AGENT_STRUCTURED_OUTPUT_ISSUE_PATH_SEGMENTS_LIMIT); offset += 1) {
|
|
65
|
+
const segment = ownData(sourcePath, offset);
|
|
66
|
+
if (typeof segment !== "string" && (typeof segment !== "number" || !Number.isFinite(segment))) break;
|
|
67
|
+
path.push(segment);
|
|
68
|
+
}
|
|
69
|
+
normalized.add(code, message, path);
|
|
70
|
+
}
|
|
71
|
+
return Object.freeze(normalized.issues.map((issue) => Object.freeze({ ...issue, path: Object.freeze([...issue.path]) })));
|
|
72
|
+
}
|
|
73
|
+
export {
|
|
74
|
+
StructuredOutputIssues,
|
|
75
|
+
normalizeAgentStructuredOutputIssues
|
|
76
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type AgentProtocolParseResult } from '../foundation/types.js';
|
|
2
|
+
import type { AgentOutputSchema } from './types.js';
|
|
3
|
+
export interface AgentOutputLimits {
|
|
4
|
+
readonly maxOutputBytes?: number;
|
|
5
|
+
}
|
|
6
|
+
export declare function parseOutputByteLimit(limits?: AgentOutputLimits): AgentProtocolParseResult<number>;
|
|
7
|
+
export declare function safeParseAgentOutputSchema(input: unknown, limits?: AgentOutputLimits): AgentProtocolParseResult<AgentOutputSchema>;
|
|
8
|
+
export declare function parseAgentOutputSchema(input: unknown, limits?: AgentOutputLimits): AgentOutputSchema;
|
|
9
|
+
export declare function trustedOutputSchema(input: AgentOutputSchema): AgentProtocolParseResult<AgentOutputSchema>;
|
|
10
|
+
//# sourceMappingURL=parsers.d.ts.map
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AgentProtocolValidationError
|
|
3
|
+
} from "../foundation/types.js";
|
|
4
|
+
import { snapshotStructuredOutputJson } from "./boundedJson.js";
|
|
5
|
+
import {
|
|
6
|
+
AGENT_OUTPUT_SCHEMA_BYTES_LIMIT,
|
|
7
|
+
AGENT_OUTPUT_SCHEMA_DEPTH_LIMIT,
|
|
8
|
+
AGENT_OUTPUT_SCHEMA_PROPERTIES_LIMIT,
|
|
9
|
+
AGENT_OUTPUT_VALUE_BYTES_LIMIT
|
|
10
|
+
} from "./constants.js";
|
|
11
|
+
import { StructuredOutputIssues } from "./issues.js";
|
|
12
|
+
import { admitOutputSchema, StructuredOutputSchemaError } from "./schemaAdmission.js";
|
|
13
|
+
const admittedSchemas = /* @__PURE__ */ new WeakSet();
|
|
14
|
+
function outputByteLimit(limits) {
|
|
15
|
+
if (limits === null || typeof limits !== "object") return void 0;
|
|
16
|
+
try {
|
|
17
|
+
const prototype = Object.getPrototypeOf(limits);
|
|
18
|
+
if (prototype !== Object.prototype && prototype !== null || Reflect.ownKeys(limits).some((key) => key !== "maxOutputBytes")) return void 0;
|
|
19
|
+
const descriptor = Object.getOwnPropertyDescriptor(limits, "maxOutputBytes");
|
|
20
|
+
if (descriptor === void 0) return AGENT_OUTPUT_VALUE_BYTES_LIMIT;
|
|
21
|
+
if (!("value" in descriptor) || !descriptor.enumerable) return void 0;
|
|
22
|
+
const value = descriptor.value;
|
|
23
|
+
if (value === void 0) return AGENT_OUTPUT_VALUE_BYTES_LIMIT;
|
|
24
|
+
return typeof value === "number" && Number.isSafeInteger(value) && value > 0 && value <= AGENT_OUTPUT_VALUE_BYTES_LIMIT ? value : void 0;
|
|
25
|
+
} catch {
|
|
26
|
+
return void 0;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
function parseOutputByteLimit(limits = {}) {
|
|
30
|
+
const maxOutputBytes = outputByteLimit(limits);
|
|
31
|
+
if (maxOutputBytes === void 0) {
|
|
32
|
+
return { success: false, issues: [{
|
|
33
|
+
code: "invalid_output_limits",
|
|
34
|
+
path: ["maxOutputBytes"],
|
|
35
|
+
message: "Output byte limit must be a positive integer within the portable profile ceiling."
|
|
36
|
+
}] };
|
|
37
|
+
}
|
|
38
|
+
return { success: true, data: maxOutputBytes };
|
|
39
|
+
}
|
|
40
|
+
function safeParseAgentOutputSchema(input, limits) {
|
|
41
|
+
const parsedLimit = parseOutputByteLimit(limits);
|
|
42
|
+
if (!parsedLimit.success) return parsedLimit;
|
|
43
|
+
const snapshot = snapshotStructuredOutputJson(input, {
|
|
44
|
+
maxBytes: AGENT_OUTPUT_SCHEMA_BYTES_LIMIT,
|
|
45
|
+
maxDepth: 3 * AGENT_OUTPUT_SCHEMA_DEPTH_LIMIT + 2,
|
|
46
|
+
maxNodes: AGENT_OUTPUT_SCHEMA_BYTES_LIMIT,
|
|
47
|
+
maxCollectionLength: AGENT_OUTPUT_SCHEMA_PROPERTIES_LIMIT
|
|
48
|
+
});
|
|
49
|
+
if (!snapshot.success) return snapshot;
|
|
50
|
+
try {
|
|
51
|
+
const schema = admitOutputSchema(snapshot.data, parsedLimit.data);
|
|
52
|
+
admittedSchemas.add(schema);
|
|
53
|
+
return { success: true, data: schema };
|
|
54
|
+
} catch (error) {
|
|
55
|
+
if (!(error instanceof StructuredOutputSchemaError)) throw error;
|
|
56
|
+
const issues = new StructuredOutputIssues();
|
|
57
|
+
issues.add("invalid_output_schema", error.message, error.path);
|
|
58
|
+
return { success: false, issues: issues.issues };
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
function parseAgentOutputSchema(input, limits) {
|
|
62
|
+
const parsed = safeParseAgentOutputSchema(input, limits);
|
|
63
|
+
if (parsed.success) return parsed.data;
|
|
64
|
+
throw new AgentProtocolValidationError(parsed.issues);
|
|
65
|
+
}
|
|
66
|
+
function trustedOutputSchema(input) {
|
|
67
|
+
return admittedSchemas.has(input) ? { success: true, data: input } : safeParseAgentOutputSchema(input);
|
|
68
|
+
}
|
|
69
|
+
export {
|
|
70
|
+
parseAgentOutputSchema,
|
|
71
|
+
parseOutputByteLimit,
|
|
72
|
+
safeParseAgentOutputSchema,
|
|
73
|
+
trustedOutputSchema
|
|
74
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { AgentJsonValue, ValidationPathSegment } from '../foundation/types.js';
|
|
2
|
+
import type { AgentOutputSchema } from './types.js';
|
|
3
|
+
export declare class StructuredOutputSchemaError extends Error {
|
|
4
|
+
readonly message: string;
|
|
5
|
+
readonly path: readonly ValidationPathSegment[];
|
|
6
|
+
constructor(message: string, path: readonly ValidationPathSegment[]);
|
|
7
|
+
}
|
|
8
|
+
export declare function admitOutputSchema(input: AgentJsonValue, maxOutputBytes?: number): AgentOutputSchema;
|
|
9
|
+
//# sourceMappingURL=schemaAdmission.d.ts.map
|