@agents24/client 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.
- package/LICENSE +21 -0
- package/README.md +47 -0
- package/compatibility.json +54 -0
- package/dist/adapters/browser.d.ts +3 -0
- package/dist/adapters/browser.js +12 -0
- package/dist/adapters/browser.js.map +1 -0
- package/dist/adapters/cloudflare.d.ts +3 -0
- package/dist/adapters/cloudflare.js +12 -0
- package/dist/adapters/cloudflare.js.map +1 -0
- package/dist/adapters/node.d.ts +3 -0
- package/dist/adapters/node.js +12 -0
- package/dist/adapters/node.js.map +1 -0
- package/dist/adapters/worker.d.ts +3 -0
- package/dist/adapters/worker.js +12 -0
- package/dist/adapters/worker.js.map +1 -0
- package/dist/base64url.d.ts +2 -0
- package/dist/capabilities.d.ts +7 -0
- package/dist/chunk-45ITVMX3.js +977 -0
- package/dist/chunk-45ITVMX3.js.map +1 -0
- package/dist/chunk-VVLMMNXI.js +163 -0
- package/dist/chunk-VVLMMNXI.js.map +1 -0
- package/dist/client.d.ts +2 -0
- package/dist/context-window.d.ts +44 -0
- package/dist/dpop.d.ts +43 -0
- package/dist/errors.d.ts +27 -0
- package/dist/generated/protocol.d.ts +70 -0
- package/dist/http.d.ts +38 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +557 -0
- package/dist/index.js.map +1 -0
- package/dist/multipart.d.ts +2 -0
- package/dist/protocol.d.ts +5 -0
- package/dist/protocol.js +146 -0
- package/dist/protocol.js.map +1 -0
- package/dist/runtime-types.d.ts +93 -0
- package/dist/sessions.d.ts +63 -0
- package/dist/stream.d.ts +20 -0
- package/dist/types.d.ts +367 -0
- package/dist/url.d.ts +5 -0
- package/package.json +88 -0
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { Agents24ProtocolError, CONTRACT_HASH, RUNTIME_PROTOCOL_VERSION, THREAD_SUMMARY_PROTOCOL_VERSION, createSseParser, parseProtocolJson, parseRuntimeEvent, parseRuntimeSsePayload, parseSseBytes, parseThreadSummarySsePayload, validateResponseBlock, validateRuntimeEvent, validateThreadSummaryEvent, } from "./generated/protocol.js";
|
|
2
|
+
export type { AbortSignalLike as ProtocolAbortSignalLike, JsonScalar, JsonValue, ProtocolErrorCategory, PublicResponseBlock, RuntimeEvent, SseParser, ThreadSummaryEvent, Utf8Decoder, } from "./generated/protocol.js";
|
|
3
|
+
export { compressionFromContextWindow, createContextWindowTracker, mergeContextWindow, mergeContextWindowUpdate, normalizeContextCompression, normalizeContextWindow, } from "./context-window.js";
|
|
4
|
+
export type { ActiveThreadRun, Attachment, AttachmentUploadResult, RunCancelResult, RunContext, RunResumeResult, ThreadDeleteResult, ThreadDetail, ThreadSummary, ThreadTurn, ThreadsResponse, ToolInputOverrides, Turn, } from "./runtime-types.js";
|
|
5
|
+
export type { ContextCompression, ContextWindow, ContextWindowConfidence, ContextWindowSource, ContextWindowStage, ContextWindowTracker, } from "./context-window.js";
|
package/dist/protocol.js
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
export { Agents24ProtocolError, CONTRACT_HASH, RUNTIME_PROTOCOL_VERSION, THREAD_SUMMARY_PROTOCOL_VERSION, createSseParser, parseProtocolJson, parseRuntimeEvent, parseRuntimeSsePayload, parseSseBytes, parseThreadSummarySsePayload, validateResponseBlock, validateRuntimeEvent, validateThreadSummaryEvent } from './chunk-VVLMMNXI.js';
|
|
2
|
+
|
|
3
|
+
// src/context-window.ts
|
|
4
|
+
var SOURCE_PRIORITY = {
|
|
5
|
+
unknown: 0,
|
|
6
|
+
heuristic_estimate: 1,
|
|
7
|
+
tokenizer_estimate: 1,
|
|
8
|
+
text_estimate: 1,
|
|
9
|
+
estimated: 1,
|
|
10
|
+
provider_cached_estimate: 1,
|
|
11
|
+
multimodal_estimate: 2,
|
|
12
|
+
hf_tokenizer: 3,
|
|
13
|
+
runtime_tokenizer: 3,
|
|
14
|
+
provider_count_api: 4,
|
|
15
|
+
provider_usage: 5,
|
|
16
|
+
exact: 5
|
|
17
|
+
};
|
|
18
|
+
var STAGE_PRIORITY = {
|
|
19
|
+
preflight: 0,
|
|
20
|
+
sent_prompt: 1,
|
|
21
|
+
final_usage: 2
|
|
22
|
+
};
|
|
23
|
+
function numberOrNull(value) {
|
|
24
|
+
return typeof value === "number" && Number.isFinite(value) ? value : null;
|
|
25
|
+
}
|
|
26
|
+
function normalizeSource(value) {
|
|
27
|
+
const raw = typeof value === "string" ? value.trim() : "";
|
|
28
|
+
return raw in SOURCE_PRIORITY ? raw : raw ? "estimated" : "unknown";
|
|
29
|
+
}
|
|
30
|
+
function normalizeStage(value) {
|
|
31
|
+
const raw = typeof value === "string" ? value.trim() : "";
|
|
32
|
+
return raw === "preflight" || raw === "sent_prompt" || raw === "final_usage" ? raw : "sent_prompt";
|
|
33
|
+
}
|
|
34
|
+
function normalizeConfidence(value) {
|
|
35
|
+
const raw = typeof value === "string" ? value.trim() : "";
|
|
36
|
+
return raw === "exact" || raw === "high" || raw === "medium" || raw === "low" || raw === "unknown" ? raw : null;
|
|
37
|
+
}
|
|
38
|
+
function stagePriority(value) {
|
|
39
|
+
return STAGE_PRIORITY[value?.stage || "sent_prompt"] ?? STAGE_PRIORITY.sent_prompt;
|
|
40
|
+
}
|
|
41
|
+
function hasRenderableWindow(value) {
|
|
42
|
+
const maxTokens = numberOrNull(value?.max_tokens);
|
|
43
|
+
return maxTokens !== null && maxTokens > 0;
|
|
44
|
+
}
|
|
45
|
+
function windowWeight(value) {
|
|
46
|
+
return value ? [stagePriority(value), SOURCE_PRIORITY[value.source] || 0] : [0, 0];
|
|
47
|
+
}
|
|
48
|
+
function normalizeContextCompression(value) {
|
|
49
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return null;
|
|
50
|
+
const payload = value;
|
|
51
|
+
return {
|
|
52
|
+
active: Boolean(payload.active),
|
|
53
|
+
reason: typeof payload.reason === "string" ? payload.reason : null,
|
|
54
|
+
input_tokens: numberOrNull(payload.input_tokens),
|
|
55
|
+
max_tokens: numberOrNull(payload.max_tokens),
|
|
56
|
+
usage_ratio: numberOrNull(payload.usage_ratio),
|
|
57
|
+
full_frame_count: numberOrNull(payload.full_frame_count),
|
|
58
|
+
compact_frame_count: numberOrNull(payload.compact_frame_count),
|
|
59
|
+
dropped_frame_count: numberOrNull(payload.dropped_frame_count),
|
|
60
|
+
artifact_ref_count: numberOrNull(payload.artifact_ref_count),
|
|
61
|
+
compression_trigger_budget: numberOrNull(payload.compression_trigger_budget),
|
|
62
|
+
compression_target_budget: numberOrNull(payload.compression_target_budget),
|
|
63
|
+
compression_target_ratio: numberOrNull(payload.compression_target_ratio),
|
|
64
|
+
threshold_used: numberOrNull(payload.threshold_used)
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
function normalizeContextWindow(value) {
|
|
68
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return null;
|
|
69
|
+
const payload = value;
|
|
70
|
+
return {
|
|
71
|
+
source: normalizeSource(payload.source),
|
|
72
|
+
run_id: typeof payload.run_id === "string" ? payload.run_id : null,
|
|
73
|
+
stage: normalizeStage(payload.stage),
|
|
74
|
+
confidence: normalizeConfidence(payload.confidence),
|
|
75
|
+
counter: typeof payload.counter === "string" ? payload.counter : null,
|
|
76
|
+
model_id: typeof payload.model_id === "string" ? payload.model_id : null,
|
|
77
|
+
max_tokens: numberOrNull(payload.max_tokens),
|
|
78
|
+
max_tokens_source: typeof payload.max_tokens_source === "string" ? payload.max_tokens_source : null,
|
|
79
|
+
input_tokens: numberOrNull(payload.input_tokens),
|
|
80
|
+
remaining_tokens: numberOrNull(payload.remaining_tokens),
|
|
81
|
+
usage_ratio: numberOrNull(payload.usage_ratio),
|
|
82
|
+
assembly: payload.assembly && typeof payload.assembly === "object" && !Array.isArray(payload.assembly) ? payload.assembly : null,
|
|
83
|
+
context_compression: normalizeContextCompression(payload.context_compression)
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
function mergeContextWindow(current, incoming) {
|
|
87
|
+
const before = current || null;
|
|
88
|
+
const next = incoming || null;
|
|
89
|
+
if (!next) return before;
|
|
90
|
+
if (!before) return next;
|
|
91
|
+
if (hasRenderableWindow(before) && !hasRenderableWindow(next)) return before;
|
|
92
|
+
if (before.run_id && next.run_id && before.run_id !== next.run_id) {
|
|
93
|
+
return stagePriority(next) >= STAGE_PRIORITY.sent_prompt ? next : before;
|
|
94
|
+
}
|
|
95
|
+
const beforeWeight = windowWeight(before);
|
|
96
|
+
const nextWeight = windowWeight(next);
|
|
97
|
+
return nextWeight[0] > beforeWeight[0] || nextWeight[0] === beforeWeight[0] && nextWeight[1] >= beforeWeight[1] ? next : before;
|
|
98
|
+
}
|
|
99
|
+
function mergeContextWindowUpdate(current, incoming) {
|
|
100
|
+
return mergeContextWindow(current, normalizeContextWindow(incoming));
|
|
101
|
+
}
|
|
102
|
+
function compressionFromContextWindow(value) {
|
|
103
|
+
if (!value) return null;
|
|
104
|
+
if (value.context_compression) return value.context_compression;
|
|
105
|
+
const assembly = value.assembly;
|
|
106
|
+
if (!assembly || typeof assembly !== "object" || Array.isArray(assembly)) return null;
|
|
107
|
+
const artifactRefs = Array.isArray(assembly.artifact_refs) ? assembly.artifact_refs : [];
|
|
108
|
+
const compactFrameCount = numberOrNull(assembly.compact_frame_count) ?? 0;
|
|
109
|
+
const droppedFrameCount = numberOrNull(assembly.dropped_frame_count) ?? 0;
|
|
110
|
+
const reason = typeof assembly.compaction_reason === "string" ? assembly.compaction_reason : "none";
|
|
111
|
+
return {
|
|
112
|
+
active: reason !== "none" || compactFrameCount > 0 || droppedFrameCount > 0,
|
|
113
|
+
reason,
|
|
114
|
+
input_tokens: value.input_tokens ?? null,
|
|
115
|
+
max_tokens: value.max_tokens ?? null,
|
|
116
|
+
usage_ratio: value.usage_ratio ?? null,
|
|
117
|
+
full_frame_count: numberOrNull(assembly.full_frame_count),
|
|
118
|
+
compact_frame_count: compactFrameCount,
|
|
119
|
+
dropped_frame_count: droppedFrameCount,
|
|
120
|
+
artifact_ref_count: artifactRefs.length,
|
|
121
|
+
compression_trigger_budget: numberOrNull(assembly.compression_trigger_budget),
|
|
122
|
+
compression_target_budget: numberOrNull(assembly.compression_target_budget),
|
|
123
|
+
compression_target_ratio: numberOrNull(assembly.compression_target_ratio),
|
|
124
|
+
threshold_used: numberOrNull(assembly.threshold_used)
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
function createContextWindowTracker(initial) {
|
|
128
|
+
let current = normalizeContextWindow(initial);
|
|
129
|
+
return {
|
|
130
|
+
get current() {
|
|
131
|
+
return current;
|
|
132
|
+
},
|
|
133
|
+
update(incoming) {
|
|
134
|
+
current = mergeContextWindowUpdate(current, incoming);
|
|
135
|
+
return current;
|
|
136
|
+
},
|
|
137
|
+
reset(next) {
|
|
138
|
+
current = normalizeContextWindow(next);
|
|
139
|
+
return current;
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export { compressionFromContextWindow, createContextWindowTracker, mergeContextWindow, mergeContextWindowUpdate, normalizeContextCompression, normalizeContextWindow };
|
|
145
|
+
//# sourceMappingURL=protocol.js.map
|
|
146
|
+
//# sourceMappingURL=protocol.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/context-window.ts"],"names":[],"mappings":";;;AAiDA,IAAM,eAAA,GAAuD;AAAA,EAC3D,OAAA,EAAS,CAAA;AAAA,EACT,kBAAA,EAAoB,CAAA;AAAA,EACpB,kBAAA,EAAoB,CAAA;AAAA,EACpB,aAAA,EAAe,CAAA;AAAA,EACf,SAAA,EAAW,CAAA;AAAA,EACX,wBAAA,EAA0B,CAAA;AAAA,EAC1B,mBAAA,EAAqB,CAAA;AAAA,EACrB,YAAA,EAAc,CAAA;AAAA,EACd,iBAAA,EAAmB,CAAA;AAAA,EACnB,kBAAA,EAAoB,CAAA;AAAA,EACpB,cAAA,EAAgB,CAAA;AAAA,EAChB,KAAA,EAAO;AACT,CAAA;AAEA,IAAM,cAAA,GAAqD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AA,GAAU;AAAE,MAAA,OAAO,OAAA;AAAA,IAAS,CAAA;AAAA,IAChC,OAAO,QAAA,EAAU;AACf,MAAA,OAAA,GAAU,wBAAA,CAAyB,SAAS,QAAQ,CAAA;AACpD,MAAA,OAAO,OAAA;AAAA,IACT,CAAA;AAAA,IACA,MAAM,IAAA,EAAM;AACV,MAAA,OAAA,GAAU,uBAAuB,IAAI,CAAA;AACrC,MAAA,OAAO,OAAA;AAAA,IACT;AAAA,GACF;AACF","file":"protocol.js","sourcesContent":["export type ContextWindowSource =\n | \"exact\"\n | \"estimated\"\n | \"provider_count_api\"\n | \"provider_usage\"\n | \"provider_cached_estimate\"\n | \"runtime_tokenizer\"\n | \"hf_tokenizer\"\n | \"multimodal_estimate\"\n | \"text_estimate\"\n | \"tokenizer_estimate\"\n | \"heuristic_estimate\"\n | \"unknown\";\n\nexport type ContextWindowStage = \"preflight\" | \"sent_prompt\" | \"final_usage\";\nexport type ContextWindowConfidence = \"exact\" | \"high\" | \"medium\" | \"low\" | \"unknown\";\n\nexport type ContextCompression = {\n active: boolean;\n reason?: string | null;\n input_tokens?: number | null;\n max_tokens?: number | null;\n usage_ratio?: number | null;\n full_frame_count?: number | null;\n compact_frame_count?: number | null;\n dropped_frame_count?: number | null;\n artifact_ref_count?: number | null;\n compression_trigger_budget?: number | null;\n compression_target_budget?: number | null;\n compression_target_ratio?: number | null;\n threshold_used?: number | null;\n};\n\nexport type ContextWindow = {\n source: ContextWindowSource;\n run_id?: string | null;\n stage?: ContextWindowStage | null;\n confidence?: ContextWindowConfidence | null;\n counter?: string | null;\n model_id?: string | null;\n max_tokens?: number | null;\n max_tokens_source?: string | null;\n input_tokens?: number | null;\n remaining_tokens?: number | null;\n usage_ratio?: number | null;\n assembly?: Record<string, unknown> | null;\n context_compression?: ContextCompression | null;\n};\n\nconst SOURCE_PRIORITY: Record<ContextWindowSource, number> = {\n unknown: 0,\n heuristic_estimate: 1,\n tokenizer_estimate: 1,\n text_estimate: 1,\n estimated: 1,\n provider_cached_estimate: 1,\n multimodal_estimate: 2,\n hf_tokenizer: 3,\n runtime_tokenizer: 3,\n provider_count_api: 4,\n provider_usage: 5,\n exact: 5,\n};\n\nconst STAGE_PRIORITY: Record<ContextWindowStage, number> = {\n preflight: 0,\n sent_prompt: 1,\n final_usage: 2,\n};\n\nfunction numberOrNull(value: unknown): number | null {\n return typeof value === \"number\" && Number.isFinite(value) ? value : null;\n}\n\nfunction normalizeSource(value: unknown): ContextWindowSource {\n const raw = typeof value === \"string\" ? value.trim() : \"\";\n return raw in SOURCE_PRIORITY ? raw as ContextWindowSource : raw ? \"estimated\" : \"unknown\";\n}\n\nfunction normalizeStage(value: unknown): ContextWindowStage {\n const raw = typeof value === \"string\" ? value.trim() : \"\";\n return raw === \"preflight\" || raw === \"sent_prompt\" || raw === \"final_usage\" ? raw : \"sent_prompt\";\n}\n\nfunction normalizeConfidence(value: unknown): ContextWindowConfidence | null {\n const raw = typeof value === \"string\" ? value.trim() : \"\";\n return raw === \"exact\" || raw === \"high\" || raw === \"medium\" || raw === \"low\" || raw === \"unknown\" ? raw : null;\n}\n\nfunction stagePriority(value: ContextWindow | null | undefined): number {\n return STAGE_PRIORITY[value?.stage || \"sent_prompt\"] ?? STAGE_PRIORITY.sent_prompt;\n}\n\nfunction hasRenderableWindow(value: ContextWindow | null | undefined): boolean {\n const maxTokens = numberOrNull(value?.max_tokens);\n return maxTokens !== null && maxTokens > 0;\n}\n\nfunction windowWeight(value: ContextWindow | null | undefined): [number, number] {\n return value ? [stagePriority(value), SOURCE_PRIORITY[value.source] || 0] : [0, 0];\n}\n\nexport function normalizeContextCompression(value: unknown): ContextCompression | null {\n if (!value || typeof value !== \"object\" || Array.isArray(value)) return null;\n const payload = value as Record<string, unknown>;\n return {\n active: Boolean(payload.active),\n reason: typeof payload.reason === \"string\" ? payload.reason : null,\n input_tokens: numberOrNull(payload.input_tokens),\n max_tokens: numberOrNull(payload.max_tokens),\n usage_ratio: numberOrNull(payload.usage_ratio),\n full_frame_count: numberOrNull(payload.full_frame_count),\n compact_frame_count: numberOrNull(payload.compact_frame_count),\n dropped_frame_count: numberOrNull(payload.dropped_frame_count),\n artifact_ref_count: numberOrNull(payload.artifact_ref_count),\n compression_trigger_budget: numberOrNull(payload.compression_trigger_budget),\n compression_target_budget: numberOrNull(payload.compression_target_budget),\n compression_target_ratio: numberOrNull(payload.compression_target_ratio),\n threshold_used: numberOrNull(payload.threshold_used),\n };\n}\n\nexport function normalizeContextWindow(value: unknown): ContextWindow | null {\n if (!value || typeof value !== \"object\" || Array.isArray(value)) return null;\n const payload = value as Record<string, unknown>;\n return {\n source: normalizeSource(payload.source),\n run_id: typeof payload.run_id === \"string\" ? payload.run_id : null,\n stage: normalizeStage(payload.stage),\n confidence: normalizeConfidence(payload.confidence),\n counter: typeof payload.counter === \"string\" ? payload.counter : null,\n model_id: typeof payload.model_id === \"string\" ? payload.model_id : null,\n max_tokens: numberOrNull(payload.max_tokens),\n max_tokens_source: typeof payload.max_tokens_source === \"string\" ? payload.max_tokens_source : null,\n input_tokens: numberOrNull(payload.input_tokens),\n remaining_tokens: numberOrNull(payload.remaining_tokens),\n usage_ratio: numberOrNull(payload.usage_ratio),\n assembly: payload.assembly && typeof payload.assembly === \"object\" && !Array.isArray(payload.assembly)\n ? payload.assembly as Record<string, unknown>\n : null,\n context_compression: normalizeContextCompression(payload.context_compression),\n };\n}\n\nexport function mergeContextWindow(\n current: ContextWindow | null | undefined,\n incoming: ContextWindow | null | undefined,\n): ContextWindow | null {\n const before = current || null;\n const next = incoming || null;\n if (!next) return before;\n if (!before) return next;\n if (hasRenderableWindow(before) && !hasRenderableWindow(next)) return before;\n if (before.run_id && next.run_id && before.run_id !== next.run_id) {\n return stagePriority(next) >= STAGE_PRIORITY.sent_prompt ? next : before;\n }\n const beforeWeight = windowWeight(before);\n const nextWeight = windowWeight(next);\n return nextWeight[0] > beforeWeight[0] || (nextWeight[0] === beforeWeight[0] && nextWeight[1] >= beforeWeight[1])\n ? next\n : before;\n}\n\nexport function mergeContextWindowUpdate(\n current: ContextWindow | null | undefined,\n incoming: unknown,\n): ContextWindow | null {\n return mergeContextWindow(current, normalizeContextWindow(incoming));\n}\n\nexport function compressionFromContextWindow(value: ContextWindow | null | undefined): ContextCompression | null {\n if (!value) return null;\n if (value.context_compression) return value.context_compression;\n const assembly = value.assembly;\n if (!assembly || typeof assembly !== \"object\" || Array.isArray(assembly)) return null;\n const artifactRefs = Array.isArray(assembly.artifact_refs) ? assembly.artifact_refs : [];\n const compactFrameCount = numberOrNull(assembly.compact_frame_count) ?? 0;\n const droppedFrameCount = numberOrNull(assembly.dropped_frame_count) ?? 0;\n const reason = typeof assembly.compaction_reason === \"string\" ? assembly.compaction_reason : \"none\";\n return {\n active: reason !== \"none\" || compactFrameCount > 0 || droppedFrameCount > 0,\n reason,\n input_tokens: value.input_tokens ?? null,\n max_tokens: value.max_tokens ?? null,\n usage_ratio: value.usage_ratio ?? null,\n full_frame_count: numberOrNull(assembly.full_frame_count),\n compact_frame_count: compactFrameCount,\n dropped_frame_count: droppedFrameCount,\n artifact_ref_count: artifactRefs.length,\n compression_trigger_budget: numberOrNull(assembly.compression_trigger_budget),\n compression_target_budget: numberOrNull(assembly.compression_target_budget),\n compression_target_ratio: numberOrNull(assembly.compression_target_ratio),\n threshold_used: numberOrNull(assembly.threshold_used),\n };\n}\n\nexport type ContextWindowTracker = {\n readonly current: ContextWindow | null;\n update(incoming: unknown): ContextWindow | null;\n reset(next?: unknown): ContextWindow | null;\n};\n\nexport function createContextWindowTracker(initial?: unknown): ContextWindowTracker {\n let current = normalizeContextWindow(initial);\n return {\n get current() { return current; },\n update(incoming) {\n current = mergeContextWindowUpdate(current, incoming);\n return current;\n },\n reset(next) {\n current = normalizeContextWindow(next);\n return current;\n },\n };\n}\n"]}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import type { PublicResponseBlock, RuntimeEvent } from "./generated/protocol.js";
|
|
2
|
+
import type { ContextCompression, ContextWindow } from "./context-window.js";
|
|
3
|
+
export type ToolInputOverrides = Record<string, {
|
|
4
|
+
defaults?: Record<string, unknown>;
|
|
5
|
+
force?: Record<string, unknown>;
|
|
6
|
+
}>;
|
|
7
|
+
export type Attachment = {
|
|
8
|
+
id: string;
|
|
9
|
+
thread_id: string | null;
|
|
10
|
+
kind: string;
|
|
11
|
+
filename: string;
|
|
12
|
+
mime_type: string;
|
|
13
|
+
byte_size: number;
|
|
14
|
+
status: string;
|
|
15
|
+
processing_error: string | null;
|
|
16
|
+
metadata: Record<string, unknown>;
|
|
17
|
+
created_at: string;
|
|
18
|
+
updated_at: string;
|
|
19
|
+
};
|
|
20
|
+
export type AttachmentUploadResult = {
|
|
21
|
+
items: Attachment[];
|
|
22
|
+
};
|
|
23
|
+
export type ActiveThreadRun = {
|
|
24
|
+
run_id: string;
|
|
25
|
+
status: string;
|
|
26
|
+
started_at: string | null;
|
|
27
|
+
created_at: string;
|
|
28
|
+
};
|
|
29
|
+
export type ThreadSummary = {
|
|
30
|
+
id: string;
|
|
31
|
+
agent_id: string | null;
|
|
32
|
+
external_user_id?: string | null;
|
|
33
|
+
external_session_id?: string | null;
|
|
34
|
+
title: string | null;
|
|
35
|
+
status: string;
|
|
36
|
+
surface: string;
|
|
37
|
+
last_run_id: string | null;
|
|
38
|
+
last_run_status: string | null;
|
|
39
|
+
active_run: ActiveThreadRun | null;
|
|
40
|
+
last_activity_at: string | null;
|
|
41
|
+
created_at: string;
|
|
42
|
+
updated_at: string;
|
|
43
|
+
};
|
|
44
|
+
export type ThreadTurn = {
|
|
45
|
+
id: string;
|
|
46
|
+
run_id: string;
|
|
47
|
+
turn_index: number;
|
|
48
|
+
user_input_text: string | null;
|
|
49
|
+
assistant_output_text: string | null;
|
|
50
|
+
status: string;
|
|
51
|
+
usage_tokens: number;
|
|
52
|
+
metadata: Record<string, unknown>;
|
|
53
|
+
response_blocks: PublicResponseBlock[];
|
|
54
|
+
attachments: Attachment[];
|
|
55
|
+
created_at: string;
|
|
56
|
+
completed_at: string | null;
|
|
57
|
+
run_events?: RuntimeEvent[];
|
|
58
|
+
};
|
|
59
|
+
export type Turn = ThreadTurn;
|
|
60
|
+
export type ThreadDetail = ThreadSummary & {
|
|
61
|
+
turns: ThreadTurn[];
|
|
62
|
+
paging: {
|
|
63
|
+
has_more: boolean;
|
|
64
|
+
next_before_turn_index: number | null;
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
export type ThreadsResponse = {
|
|
68
|
+
items: ThreadSummary[];
|
|
69
|
+
total: number;
|
|
70
|
+
};
|
|
71
|
+
export type RunContext = {
|
|
72
|
+
run_id: string;
|
|
73
|
+
thread_id: string | null;
|
|
74
|
+
context_window: ContextWindow | null;
|
|
75
|
+
context_compression: ContextCompression | null;
|
|
76
|
+
run_usage: Record<string, unknown>;
|
|
77
|
+
};
|
|
78
|
+
export type RunCancelResult = {
|
|
79
|
+
run_id: string;
|
|
80
|
+
status: string;
|
|
81
|
+
thread_id?: string | null;
|
|
82
|
+
};
|
|
83
|
+
export type RunResumeResult = {
|
|
84
|
+
run_id: string;
|
|
85
|
+
interrupt_id: string;
|
|
86
|
+
run_status: string;
|
|
87
|
+
resolution_status: string;
|
|
88
|
+
idempotent: boolean;
|
|
89
|
+
thread_id?: string | null;
|
|
90
|
+
};
|
|
91
|
+
export type ThreadDeleteResult = {
|
|
92
|
+
deleted: boolean;
|
|
93
|
+
};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { AbortSignalLike, ClientSessionAccess, ClientSessionProvider, ClientSessionStorage, Clock, DpopKeyProvider, FetchLike, IdProvider, SessionRefreshCoordinator, SessionRefreshFenceStorage, TelemetrySink, WaitCapability } from "./types.js";
|
|
2
|
+
export interface FencedRefreshCoordinatorOptions {
|
|
3
|
+
storage: SessionRefreshFenceStorage;
|
|
4
|
+
clock?: Clock;
|
|
5
|
+
ids?: IdProvider;
|
|
6
|
+
ownerId?: string;
|
|
7
|
+
leaseDurationMs?: number;
|
|
8
|
+
pollIntervalMs?: number;
|
|
9
|
+
wait?: WaitCapability;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Coordinates refresh-grant rotation across tabs/processes through an injected
|
|
13
|
+
* atomic compare-and-swap store. Takeovers retain the same operation ID so a
|
|
14
|
+
* timed-out owner and its successor address one server idempotency record.
|
|
15
|
+
*/
|
|
16
|
+
export declare function createFencedRefreshCoordinator(options: FencedRefreshCoordinatorOptions): SessionRefreshCoordinator;
|
|
17
|
+
export declare function createInMemoryRefreshCoordinator(): SessionRefreshCoordinator;
|
|
18
|
+
export declare function createStaticSessionProvider(access: ClientSessionAccess): ClientSessionProvider;
|
|
19
|
+
export interface ManagedSessionProviderOptions {
|
|
20
|
+
baseUrl: string;
|
|
21
|
+
deploymentId: string;
|
|
22
|
+
fetch?: FetchLike;
|
|
23
|
+
dpopKeyProvider?: DpopKeyProvider | undefined;
|
|
24
|
+
storage?: ClientSessionStorage;
|
|
25
|
+
coordinator?: SessionRefreshCoordinator;
|
|
26
|
+
clock?: Clock;
|
|
27
|
+
ids?: IdProvider;
|
|
28
|
+
telemetry?: TelemetrySink;
|
|
29
|
+
mint(input: {
|
|
30
|
+
fetch: FetchLike;
|
|
31
|
+
url: string;
|
|
32
|
+
dpopKeyProvider?: DpopKeyProvider | undefined;
|
|
33
|
+
signal?: AbortSignalLike | undefined;
|
|
34
|
+
}): Promise<unknown>;
|
|
35
|
+
}
|
|
36
|
+
export declare function createManagedSessionProvider(options: ManagedSessionProviderOptions): ClientSessionProvider;
|
|
37
|
+
export interface AnonymousSessionProviderOptions extends Omit<ManagedSessionProviderOptions, "mint"> {
|
|
38
|
+
persistent?: boolean;
|
|
39
|
+
nativeProfileId?: string;
|
|
40
|
+
requestedCapabilities?: readonly string[];
|
|
41
|
+
attestation?: string;
|
|
42
|
+
}
|
|
43
|
+
export declare function createAnonymousSessionProvider(options: AnonymousSessionProviderOptions): ClientSessionProvider;
|
|
44
|
+
export interface HostedOidcSessionProvider extends ClientSessionProvider {
|
|
45
|
+
beginAuthorization(input: {
|
|
46
|
+
redirectUri: string;
|
|
47
|
+
codeChallenge: string;
|
|
48
|
+
nativeProfileId?: string;
|
|
49
|
+
signal?: AbortSignalLike;
|
|
50
|
+
}): Promise<{
|
|
51
|
+
authorizationUrl: string;
|
|
52
|
+
}>;
|
|
53
|
+
exchange(input: {
|
|
54
|
+
code: string;
|
|
55
|
+
codeVerifier: string;
|
|
56
|
+
signal?: AbortSignalLike;
|
|
57
|
+
}): Promise<ClientSessionAccess>;
|
|
58
|
+
}
|
|
59
|
+
export interface HostedOidcSessionProviderOptions extends Omit<ManagedSessionProviderOptions, "mint"> {
|
|
60
|
+
dpopKeyProvider: DpopKeyProvider;
|
|
61
|
+
redirectUri?: string;
|
|
62
|
+
}
|
|
63
|
+
export declare function createHostedOidcSessionProvider(options: HostedOidcSessionProviderOptions): HostedOidcSessionProvider;
|
package/dist/stream.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { AbortSignalLike, FetchResponseLike, RuntimeEventHandler, StreamResult, TextDecoderLike, ThreadSummaryEventHandler } from "./types.js";
|
|
2
|
+
export type RuntimeStreamState = StreamResult & {
|
|
3
|
+
detachReason?: "token_expired" | "revoked" | "policy_changed" | "server_detach";
|
|
4
|
+
};
|
|
5
|
+
export declare function consumeRuntimeStream(input: {
|
|
6
|
+
response: FetchResponseLike;
|
|
7
|
+
signal?: AbortSignalLike;
|
|
8
|
+
decoder: TextDecoderLike;
|
|
9
|
+
onEvent: RuntimeEventHandler;
|
|
10
|
+
afterCursor?: number;
|
|
11
|
+
onProgress?: (state: RuntimeStreamState) => void;
|
|
12
|
+
}): Promise<RuntimeStreamState>;
|
|
13
|
+
export declare function consumeThreadSummaryStream(input: {
|
|
14
|
+
response: FetchResponseLike;
|
|
15
|
+
signal?: AbortSignalLike;
|
|
16
|
+
decoder: TextDecoderLike;
|
|
17
|
+
onEvent: ThreadSummaryEventHandler;
|
|
18
|
+
afterCursor?: number;
|
|
19
|
+
onCursor?: (cursor: number) => void;
|
|
20
|
+
}): Promise<number | null>;
|