@zoowork-ai/sdk 0.8.0 → 0.10.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/CHANGELOG.md +54 -2
- package/README.md +140 -44
- package/dist/client.d.ts +46 -20
- package/dist/client.js +14 -7
- package/dist/developer-api.d.ts +200 -0
- package/dist/developer-api.js +42 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -0
- package/dist/secret-redaction.d.ts +2 -0
- package/dist/secret-redaction.js +10 -0
- package/dist/sse.js +39 -29
- package/dist/webhooks.d.ts +430 -0
- package/dist/webhooks.js +410 -0
- package/package.json +1 -1
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import type { ApprovalRecord, CustomToolCallRecord, Ownership } from './client.js';
|
|
2
|
+
import type { WebhookEventType } from './webhooks.js';
|
|
3
|
+
/** Response fields retain their API spelling; unknown additions are preserved. */
|
|
4
|
+
export type ApiObject = Record<string, unknown>;
|
|
5
|
+
export interface CursorOptions {
|
|
6
|
+
cursor?: string;
|
|
7
|
+
limit?: number;
|
|
8
|
+
}
|
|
9
|
+
export interface ActionListOptions extends CursorOptions {
|
|
10
|
+
status?: 'pending';
|
|
11
|
+
sessionId?: string;
|
|
12
|
+
}
|
|
13
|
+
export interface ApprovalPage extends ApiObject {
|
|
14
|
+
approvals: ApprovalRecord[];
|
|
15
|
+
has_more: boolean;
|
|
16
|
+
next_cursor: string | null;
|
|
17
|
+
}
|
|
18
|
+
export interface CustomToolCallPage extends ApiObject {
|
|
19
|
+
custom_tool_calls: CustomToolCallRecord[];
|
|
20
|
+
has_more: boolean;
|
|
21
|
+
next_cursor: string | null;
|
|
22
|
+
}
|
|
23
|
+
export interface WorkspaceFileEntry extends ApiObject {
|
|
24
|
+
name: string;
|
|
25
|
+
type: string;
|
|
26
|
+
size?: number;
|
|
27
|
+
updated_at?: string;
|
|
28
|
+
}
|
|
29
|
+
export type WorkspaceFile = (ApiObject & {
|
|
30
|
+
path: string;
|
|
31
|
+
content: string;
|
|
32
|
+
}) | (ApiObject & {
|
|
33
|
+
path: string;
|
|
34
|
+
entries: WorkspaceFileEntry[];
|
|
35
|
+
});
|
|
36
|
+
export interface AgentDatabase extends ApiObject {
|
|
37
|
+
status: 'not_provisioned' | 'ready';
|
|
38
|
+
tables?: {
|
|
39
|
+
name: unknown;
|
|
40
|
+
kind: unknown;
|
|
41
|
+
}[];
|
|
42
|
+
}
|
|
43
|
+
export interface AgentDatabaseRows extends ApiObject {
|
|
44
|
+
status: 'not_provisioned' | 'ready';
|
|
45
|
+
table?: string;
|
|
46
|
+
schema?: unknown[][];
|
|
47
|
+
columns?: string[];
|
|
48
|
+
rows?: unknown[][];
|
|
49
|
+
limit?: number;
|
|
50
|
+
offset?: number;
|
|
51
|
+
}
|
|
52
|
+
export interface UsageOptions {
|
|
53
|
+
range?: '24h' | '7d' | '30d';
|
|
54
|
+
timezone?: string;
|
|
55
|
+
groupBy?: 'session' | 'api_key';
|
|
56
|
+
view?: 'groups' | 'records' | 'both';
|
|
57
|
+
sessionId?: string;
|
|
58
|
+
apiKeyId?: string;
|
|
59
|
+
rootSessionId?: string;
|
|
60
|
+
attribution?: 'exact' | 'shared' | 'non_api' | 'unattributed';
|
|
61
|
+
page?: number;
|
|
62
|
+
perPage?: number;
|
|
63
|
+
asOf?: string;
|
|
64
|
+
snapshot?: string;
|
|
65
|
+
cursor?: string;
|
|
66
|
+
}
|
|
67
|
+
export interface UsageResult extends ApiObject {
|
|
68
|
+
groups?: ApiObject[];
|
|
69
|
+
records?: ApiObject[];
|
|
70
|
+
}
|
|
71
|
+
export interface RunOutputArtifact extends ApiObject {
|
|
72
|
+
artifact_id: string | null;
|
|
73
|
+
name: string;
|
|
74
|
+
content_type: string;
|
|
75
|
+
size: number;
|
|
76
|
+
}
|
|
77
|
+
export interface RunOutputItem extends ApiObject {
|
|
78
|
+
seq: number;
|
|
79
|
+
kind: string;
|
|
80
|
+
source: string;
|
|
81
|
+
text?: string;
|
|
82
|
+
artifacts: RunOutputArtifact[];
|
|
83
|
+
}
|
|
84
|
+
export interface RunOutput extends ApiObject {
|
|
85
|
+
run: ApiObject;
|
|
86
|
+
items: RunOutputItem[];
|
|
87
|
+
has_more: boolean;
|
|
88
|
+
next_cursor: string | null;
|
|
89
|
+
output_complete: boolean;
|
|
90
|
+
}
|
|
91
|
+
export interface AgentWebhookInput {
|
|
92
|
+
url: string;
|
|
93
|
+
event_types: Exclude<WebhookEventType, 'webhook.test'>[];
|
|
94
|
+
description?: string | null;
|
|
95
|
+
session_scope?: 'api' | 'all';
|
|
96
|
+
enabled?: boolean;
|
|
97
|
+
}
|
|
98
|
+
export interface AgentWebhookEndpoint extends ApiObject {
|
|
99
|
+
id: string;
|
|
100
|
+
url?: string;
|
|
101
|
+
event_types?: string[];
|
|
102
|
+
description?: string | null;
|
|
103
|
+
session_scope?: string;
|
|
104
|
+
enabled?: boolean;
|
|
105
|
+
}
|
|
106
|
+
export interface AgentWebhookPage extends ApiObject {
|
|
107
|
+
webhooks: AgentWebhookEndpoint[];
|
|
108
|
+
has_more: boolean;
|
|
109
|
+
next_cursor: string | null;
|
|
110
|
+
}
|
|
111
|
+
export interface AgentWebhookCreated extends ApiObject {
|
|
112
|
+
endpoint: AgentWebhookEndpoint;
|
|
113
|
+
signing_secret: string | null;
|
|
114
|
+
signing_secret_version: number;
|
|
115
|
+
signing_secret_available: boolean;
|
|
116
|
+
}
|
|
117
|
+
export interface AgentWebhookSecretRotation extends ApiObject {
|
|
118
|
+
endpoint_id: string;
|
|
119
|
+
signing_secret: string | null;
|
|
120
|
+
signing_secret_version: number;
|
|
121
|
+
signing_secret_available: boolean;
|
|
122
|
+
previous_versions?: unknown[];
|
|
123
|
+
}
|
|
124
|
+
export interface WebhookDeliveryOptions extends CursorOptions {
|
|
125
|
+
status?: 'pending' | 'in_flight' | 'succeeded' | 'dead' | 'cancelled';
|
|
126
|
+
eventType?: string;
|
|
127
|
+
eventId?: string;
|
|
128
|
+
sessionId?: string;
|
|
129
|
+
runId?: string;
|
|
130
|
+
scheduleId?: string;
|
|
131
|
+
}
|
|
132
|
+
export interface WebhookDeliveryPage extends ApiObject {
|
|
133
|
+
deliveries: ApiObject[];
|
|
134
|
+
has_more: boolean;
|
|
135
|
+
next_cursor: string | null;
|
|
136
|
+
}
|
|
137
|
+
/** These receipts acknowledge queuing, not receiver or business processing. */
|
|
138
|
+
export interface WebhookTestReceipt extends ApiObject {
|
|
139
|
+
object: 'webhook_test';
|
|
140
|
+
endpoint_id: string;
|
|
141
|
+
receipt_id: string;
|
|
142
|
+
}
|
|
143
|
+
export interface WebhookRedeliveryReceipt extends ApiObject {
|
|
144
|
+
object: 'webhook_redelivery';
|
|
145
|
+
delivery_id: string;
|
|
146
|
+
round: number;
|
|
147
|
+
deadline_at: string;
|
|
148
|
+
}
|
|
149
|
+
export interface WebhookBatchRedeliveryReceipt extends ApiObject {
|
|
150
|
+
object: 'webhook_redelivery_batch';
|
|
151
|
+
count: number;
|
|
152
|
+
}
|
|
153
|
+
export interface WebhookBatchRedeliveryInput {
|
|
154
|
+
status?: 'dead';
|
|
155
|
+
since?: string | null;
|
|
156
|
+
event_types?: string[] | null;
|
|
157
|
+
limit?: number;
|
|
158
|
+
}
|
|
159
|
+
export interface DeveloperApi {
|
|
160
|
+
getWorkspaceFile(agentId: string, path: string, opts?: {
|
|
161
|
+
showHidden?: boolean;
|
|
162
|
+
}): Promise<WorkspaceFile>;
|
|
163
|
+
writeWorkspaceFile(agentId: string, path: string, content: string): Promise<ApiObject>;
|
|
164
|
+
getWorkspaceFileContent(agentId: string, path: string, opts?: {
|
|
165
|
+
download?: boolean;
|
|
166
|
+
}): Promise<Uint8Array>;
|
|
167
|
+
getAgentDatabase(agentId: string): Promise<AgentDatabase>;
|
|
168
|
+
getAgentDatabaseRows(agentId: string, tableName: string, opts?: {
|
|
169
|
+
limit?: number;
|
|
170
|
+
offset?: number;
|
|
171
|
+
}): Promise<AgentDatabaseRows>;
|
|
172
|
+
getUsage(opts?: UsageOptions): Promise<UsageResult>;
|
|
173
|
+
getRunOutput(agentId: string, sessionId: string, runId: string, opts?: CursorOptions): Promise<RunOutput>;
|
|
174
|
+
getApproval(agentId: string, approvalId: string): Promise<ApprovalRecord>;
|
|
175
|
+
getCustomToolCall(agentId: string, callId: string): Promise<CustomToolCallRecord>;
|
|
176
|
+
listApprovalPage(agentId: string, opts?: ActionListOptions): Promise<ApprovalPage>;
|
|
177
|
+
listCustomToolCallPage(agentId: string, opts?: ActionListOptions): Promise<CustomToolCallPage>;
|
|
178
|
+
listAgentWebhooks(agentId: string, opts?: CursorOptions): Promise<AgentWebhookPage>;
|
|
179
|
+
createAgentWebhook(agentId: string, input: AgentWebhookInput, idempotencyKey: string): Promise<AgentWebhookCreated>;
|
|
180
|
+
getAgentWebhook(agentId: string, webhookId: string): Promise<AgentWebhookEndpoint>;
|
|
181
|
+
updateAgentWebhook(agentId: string, webhookId: string, input: Partial<AgentWebhookInput>): Promise<AgentWebhookEndpoint>;
|
|
182
|
+
deleteAgentWebhook(agentId: string, webhookId: string): Promise<void>;
|
|
183
|
+
rotateAgentWebhookSecret(agentId: string, webhookId: string, input: {
|
|
184
|
+
revoke_previous_after: 0 | 86400;
|
|
185
|
+
}, idempotencyKey: string): Promise<AgentWebhookSecretRotation>;
|
|
186
|
+
testAgentWebhook(agentId: string, webhookId: string, idempotencyKey: string): Promise<WebhookTestReceipt>;
|
|
187
|
+
getAgentWebhookEvent(agentId: string, eventId: string): Promise<ApiObject>;
|
|
188
|
+
listAgentWebhookDeliveries(agentId: string, webhookId: string, opts?: WebhookDeliveryOptions): Promise<WebhookDeliveryPage>;
|
|
189
|
+
getAgentWebhookDelivery(agentId: string, webhookId: string, deliveryId: string): Promise<ApiObject>;
|
|
190
|
+
redeliverAgentWebhookDelivery(agentId: string, webhookId: string, deliveryId: string, idempotencyKey: string): Promise<WebhookRedeliveryReceipt>;
|
|
191
|
+
redeliverAgentWebhookDeliveries(agentId: string, webhookId: string, input: WebhookBatchRedeliveryInput, idempotencyKey: string): Promise<WebhookBatchRedeliveryReceipt>;
|
|
192
|
+
}
|
|
193
|
+
type Request = <T>(path: string, init?: {
|
|
194
|
+
method?: string;
|
|
195
|
+
body?: string;
|
|
196
|
+
headers?: Record<string, string>;
|
|
197
|
+
}) => Promise<T>;
|
|
198
|
+
/** Uses the same authentication/error transport as the existing client. Never retries writes. */
|
|
199
|
+
export declare function createDeveloperApi(json: Request, bytes: (path: string) => Promise<Uint8Array>, selectors: (agentId: string) => Promise<Pick<Ownership, 'owner_uid' | 'org_id'>>): DeveloperApi;
|
|
200
|
+
export {};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
const segment = encodeURIComponent;
|
|
2
|
+
function query(params) {
|
|
3
|
+
const result = new URLSearchParams();
|
|
4
|
+
for (const [key, value] of Object.entries(params))
|
|
5
|
+
if (value !== undefined)
|
|
6
|
+
result.set(key, String(value));
|
|
7
|
+
return result.size ? `?${result}` : '';
|
|
8
|
+
}
|
|
9
|
+
function post(body, idempotencyKey) {
|
|
10
|
+
return { method: 'POST', body: JSON.stringify(body), ...(idempotencyKey !== undefined ? { headers: { 'Idempotency-Key': idempotencyKey } } : {}) };
|
|
11
|
+
}
|
|
12
|
+
/** Uses the same authentication/error transport as the existing client. Never retries writes. */
|
|
13
|
+
export function createDeveloperApi(json, bytes, selectors) {
|
|
14
|
+
const agent = (id) => `/agents/${segment(id)}`;
|
|
15
|
+
const webhooks = (id) => `${agent(id)}/webhooks`;
|
|
16
|
+
const endpoint = (id, webhookId) => `${webhooks(id)}/${segment(webhookId)}`;
|
|
17
|
+
return {
|
|
18
|
+
getWorkspaceFile: async (id, path, opts = {}) => json(`${agent(id)}/files${query({ ...await selectors(id), path, showHidden: opts.showHidden })}`),
|
|
19
|
+
writeWorkspaceFile: (id, path, content) => json(`${agent(id)}/files`, post({ path, content })),
|
|
20
|
+
getWorkspaceFileContent: async (id, path, opts = {}) => bytes(`${agent(id)}/files/content${query({ ...await selectors(id), path, download: opts.download })}`),
|
|
21
|
+
getAgentDatabase: (id) => json(`${agent(id)}/database`),
|
|
22
|
+
getAgentDatabaseRows: (id, table, opts = {}) => json(`${agent(id)}/database/tables/${segment(table)}/rows${query({ limit: opts.limit, offset: opts.offset })}`),
|
|
23
|
+
getUsage: (opts = {}) => json(`/usage${query({ range: opts.range, timezone: opts.timezone, group_by: opts.groupBy, view: opts.view, session_id: opts.sessionId, api_key_id: opts.apiKeyId, root_session_id: opts.rootSessionId, attribution: opts.attribution, page: opts.page, per_page: opts.perPage, as_of: opts.asOf, snapshot: opts.snapshot, cursor: opts.cursor })}`),
|
|
24
|
+
getRunOutput: (id, sid, rid, opts = {}) => json(`${agent(id)}/sessions/${segment(sid)}/runs/${segment(rid)}/output${query({ cursor: opts.cursor, limit: opts.limit })}`),
|
|
25
|
+
getApproval: (id, aid) => json(`${agent(id)}/approvals/${segment(aid)}`),
|
|
26
|
+
getCustomToolCall: (id, cid) => json(`${agent(id)}/custom_tool_calls/${segment(cid)}`),
|
|
27
|
+
listApprovalPage: (id, opts = {}) => json(`${agent(id)}/approvals${query({ status: opts.status, session_id: opts.sessionId, cursor: opts.cursor, limit: opts.limit ?? 50 })}`),
|
|
28
|
+
listCustomToolCallPage: (id, opts = {}) => json(`${agent(id)}/custom_tool_calls${query({ status: opts.status, session_id: opts.sessionId, cursor: opts.cursor, limit: opts.limit ?? 50 })}`),
|
|
29
|
+
listAgentWebhooks: (id, opts = {}) => json(`${webhooks(id)}${query({ cursor: opts.cursor, limit: opts.limit })}`),
|
|
30
|
+
createAgentWebhook: (id, input, key) => json(webhooks(id), post(input, key)),
|
|
31
|
+
getAgentWebhook: (id, wid) => json(endpoint(id, wid)),
|
|
32
|
+
updateAgentWebhook: (id, wid, input) => json(`${endpoint(id, wid)}/update`, post(input)),
|
|
33
|
+
deleteAgentWebhook: async (id, wid) => { await json(`${endpoint(id, wid)}/delete`, post({})); },
|
|
34
|
+
rotateAgentWebhookSecret: (id, wid, input, key) => json(`${endpoint(id, wid)}/rotate-secret`, post(input, key)),
|
|
35
|
+
testAgentWebhook: (id, wid, key) => json(`${endpoint(id, wid)}/test`, post({}, key)),
|
|
36
|
+
getAgentWebhookEvent: (id, eid) => json(`${webhooks(id)}/events/${segment(eid)}`),
|
|
37
|
+
listAgentWebhookDeliveries: (id, wid, opts = {}) => json(`${endpoint(id, wid)}/deliveries${query({ cursor: opts.cursor, limit: opts.limit, status: opts.status, event_type: opts.eventType, event_id: opts.eventId, session_id: opts.sessionId, run_id: opts.runId, schedule_id: opts.scheduleId })}`),
|
|
38
|
+
getAgentWebhookDelivery: (id, wid, did) => json(`${endpoint(id, wid)}/deliveries/${segment(did)}`),
|
|
39
|
+
redeliverAgentWebhookDelivery: (id, wid, did, key) => json(`${endpoint(id, wid)}/deliveries/${segment(did)}/redeliver`, post({}, key)),
|
|
40
|
+
redeliverAgentWebhookDeliveries: (id, wid, input, key) => json(`${endpoint(id, wid)}/deliveries/redeliver`, post(input, key)),
|
|
41
|
+
};
|
|
42
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
export { createZooworkClient, DEFAULT_BASE_URL, ZooworkError, type ZooworkClient, type ZooworkConfig, type ZooworkAuth, type Ownership, type ModelInfo, type AgentResource, type AgentRecord, type AgentListParams, type AgentPage, type AgentPagePromise, type AgentStatus, type AgentSkill, type AgentChannel, type AgentChannelCapabilitySync, type AgentChannelCapabilities, type FeishuChannelProviderStatus, type FeishuDocumentsCapability, type ChannelPlatform, type AddChannelPlatform, type GuidedSetupPlatform, type AddChannelInput, type UpdateChannelInput, type ChannelSetupInput, type ChannelSetupSession, type ChannelPollResult, type FeishuSetupInput, type FeishuSetupSession, type FeishuPollResult, type McpContextConfig, type McpServerDeclaration, type McpToolPermission, type McpToolPermissionOverride, type CustomToolDeclaration, type CustomToolResultImageMimeType, type CustomToolResultContent, type CustomToolResultEvent, type SkillRecord, type SkillVersionRecord, type SessionRecord, type SessionListPageOptions, type SessionListPage, type SessionHistoryEntry, type SessionEvent, type SessionEventPage, type OutboundEvent, type PostEventReceipt, type ApprovalDecision, type ApprovalRecord, type CustomToolCallStatus, type CustomToolCallRecord, type ArtifactPage, type ArtifactRecord, type ArtifactStatus, type OutcomeConfig, type OutcomeEvaluator, type SystemPromptDeclaration, type SystemPromptInfo, type SystemPromptPreview, type SystemPromptPreviewInput, type SystemPromptUpgrade, type ScheduleSpec, type SchedulePayload, type ScheduleInput, type ScheduleUpdate, type ScheduleRecord, type ScheduleRun, type WakeResult, type ExecResult, type EnvironmentConfig, type EnvironmentResource, type EnvironmentRecord, type EnvironmentVersionRecord, } from './client.js';
|
|
2
2
|
export { SESSION_EVENT_TYPES, type SessionEventType, PUBLIC_INPUT_EVENT_TYPES, type PublicInputEventType, normalizeEvent, isRunFinished, runOutcome, messageText, assistantText, thinkingText, customToolUse, type CustomToolUse, toolCall, type ToolCall, } from './events.js';
|
|
3
3
|
export { parseSSE, type SSEMessage } from './sse.js';
|
|
4
|
+
export { WEBHOOK_EVENT_TYPES, WEBHOOK_SCHEDULE_CONFIG_EVENT_TYPES, type WebhookEventType, isKnownWebhookEventType, knownWebhookEvent, verifyWebhookSignature, unwrapWebhook, signWebhook, ZooworkWebhookError, type WebhookErrorCode, WEBHOOK_ID_HEADER, WEBHOOK_TIMESTAMP_HEADER, WEBHOOK_SIGNATURE_HEADER, WEBHOOK_SECRET_ENV, WEBHOOK_TOLERANCE_SECONDS, WEBHOOK_DEFAULT_MAX_BODY_BYTES, type WebhookEvent, type WebhookEventFor, type KnownWebhookEvent, type WebhookEventData, type WebhookEventDataByType, type WebhookEventAttribution, type WebhookScheduleRunRef, type WebhookWaitingOnRef, type WebhookRunEventData, type WebhookRunStartedData, type WebhookRunFinishedData, type WebhookRunYieldedData, type WebhookApprovalEventData, type WebhookApprovalRequestedData, type WebhookApprovalResolvedData, type WebhookCustomToolEventData, type WebhookCustomToolRequestedData, type WebhookCustomToolResolvedData, type WebhookOutcomeEvaluatedData, type WebhookSessionCreatedData, type WebhookSessionArchivedData, type WebhookSessionDeletedData, type WebhookScheduleFireData, type WebhookScheduleDispatchedData, type WebhookScheduleDispatchFailedData, type WebhookScheduleSkippedData, type WebhookScheduleFinishedData, type WebhookScheduleConfigData, type WebhookTestData, type WebhookHeaders, type WebhookHeaderSource, type WebhookSignatureHeaders, type VerifyWebhookInput, type VerifiedWebhook, type SignWebhookInput, } from './webhooks.js';
|
|
5
|
+
export type { ApiObject, CursorOptions, ActionListOptions, ApprovalPage, CustomToolCallPage, WorkspaceFileEntry, WorkspaceFile, AgentDatabase, AgentDatabaseRows, UsageOptions, UsageResult, RunOutputArtifact, RunOutputItem, RunOutput, AgentWebhookInput, AgentWebhookEndpoint, AgentWebhookPage, AgentWebhookCreated, AgentWebhookSecretRotation, WebhookDeliveryOptions, WebhookDeliveryPage, WebhookTestReceipt, WebhookRedeliveryReceipt, WebhookBatchRedeliveryReceipt, WebhookBatchRedeliveryInput, DeveloperApi, } from './developer-api.js';
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
export { createZooworkClient, DEFAULT_BASE_URL, ZooworkError, } from './client.js';
|
|
2
2
|
export { SESSION_EVENT_TYPES, PUBLIC_INPUT_EVENT_TYPES, normalizeEvent, isRunFinished, runOutcome, messageText, assistantText, thinkingText, customToolUse, toolCall, } from './events.js';
|
|
3
3
|
export { parseSSE } from './sse.js';
|
|
4
|
+
export { WEBHOOK_EVENT_TYPES, WEBHOOK_SCHEDULE_CONFIG_EVENT_TYPES, isKnownWebhookEventType, knownWebhookEvent, verifyWebhookSignature, unwrapWebhook, signWebhook, ZooworkWebhookError, WEBHOOK_ID_HEADER, WEBHOOK_TIMESTAMP_HEADER, WEBHOOK_SIGNATURE_HEADER, WEBHOOK_SECRET_ENV, WEBHOOK_TOLERANCE_SECONDS, WEBHOOK_DEFAULT_MAX_BODY_BYTES, } from './webhooks.js';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** Fixture safety only; authentication treats keys as opaque values. */
|
|
2
|
+
export function redactApiKeys(text, knownKey) {
|
|
3
|
+
let clean = text;
|
|
4
|
+
if (knownKey && knownKey.length >= 8)
|
|
5
|
+
clean = clean.split(knownKey).join('REDACTED');
|
|
6
|
+
return clean
|
|
7
|
+
.replace(/zwp_live_[A-Za-z0-9_-]{8,}/g, 'zwp_live_REDACTED')
|
|
8
|
+
.replace(/zct_[A-Za-z0-9_-]{8,}/g, 'zct_REDACTED')
|
|
9
|
+
.replace(/(Bearer )[A-Za-z0-9._~+/-]{8,}=*/g, '$1REDACTED');
|
|
10
|
+
}
|
package/dist/sse.js
CHANGED
|
@@ -30,36 +30,46 @@ export async function* parseSSE(body) {
|
|
|
30
30
|
dataLines = [];
|
|
31
31
|
return msg;
|
|
32
32
|
};
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
33
|
+
try {
|
|
34
|
+
for (;;) {
|
|
35
|
+
const { done, value } = await reader.read();
|
|
36
|
+
if (done)
|
|
37
|
+
break;
|
|
38
|
+
buf += dec.decode(value, { stream: true });
|
|
39
|
+
let i;
|
|
40
|
+
while ((i = buf.indexOf('\n')) >= 0) {
|
|
41
|
+
const raw = buf.slice(0, i);
|
|
42
|
+
buf = buf.slice(i + 1);
|
|
43
|
+
const line = raw.endsWith('\r') ? raw.slice(0, -1) : raw;
|
|
44
|
+
if (line === '') {
|
|
45
|
+
const m = flush();
|
|
46
|
+
if (m)
|
|
47
|
+
yield m;
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
if (line.startsWith(':'))
|
|
51
|
+
continue;
|
|
52
|
+
const c = line.indexOf(':');
|
|
53
|
+
const field = c === -1 ? line : line.slice(0, c);
|
|
54
|
+
const val = c === -1 ? '' : line.slice(c + 1).replace(/^ /, '');
|
|
55
|
+
if (field === 'event')
|
|
56
|
+
event = val;
|
|
57
|
+
else if (field === 'data')
|
|
58
|
+
dataLines.push(val);
|
|
59
|
+
else if (field === 'id')
|
|
60
|
+
id = val;
|
|
48
61
|
}
|
|
49
|
-
if (line.startsWith(':'))
|
|
50
|
-
continue;
|
|
51
|
-
const c = line.indexOf(':');
|
|
52
|
-
const field = c === -1 ? line : line.slice(0, c);
|
|
53
|
-
const val = c === -1 ? '' : line.slice(c + 1).replace(/^ /, '');
|
|
54
|
-
if (field === 'event')
|
|
55
|
-
event = val;
|
|
56
|
-
else if (field === 'data')
|
|
57
|
-
dataLines.push(val);
|
|
58
|
-
else if (field === 'id')
|
|
59
|
-
id = val;
|
|
60
62
|
}
|
|
63
|
+
const m = flush();
|
|
64
|
+
if (m)
|
|
65
|
+
yield m;
|
|
66
|
+
}
|
|
67
|
+
finally {
|
|
68
|
+
// A session stream outlives each turn. Closing the generator must close its HTTP body.
|
|
69
|
+
try {
|
|
70
|
+
await reader.cancel();
|
|
71
|
+
}
|
|
72
|
+
catch { /* Preserve the original parse/transport failure. */ }
|
|
73
|
+
reader.releaseLock();
|
|
61
74
|
}
|
|
62
|
-
const m = flush();
|
|
63
|
-
if (m)
|
|
64
|
-
yield m;
|
|
65
75
|
}
|