@pstdio/pocketcoder-sdk 0.9.0 → 0.11.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/README.md +19 -18
- package/dist/index.d.ts +1347 -2149
- package/dist/index.js +164 -206
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -110,7 +110,8 @@ const WorkloadCapabilitySchema = z.enum([
|
|
|
110
110
|
"revocable-preview-grants",
|
|
111
111
|
"workspace-cancel",
|
|
112
112
|
"unknown-outcome",
|
|
113
|
-
"parallel-conversations"
|
|
113
|
+
"parallel-conversations",
|
|
114
|
+
"history-seed"
|
|
114
115
|
]);
|
|
115
116
|
const WorkloadProfileSchema = z.enum([
|
|
116
117
|
"finite-process",
|
|
@@ -241,8 +242,6 @@ const SCOPES = [
|
|
|
241
242
|
"terminal:read",
|
|
242
243
|
"sessions:read",
|
|
243
244
|
"sessions:write",
|
|
244
|
-
"budgets:read",
|
|
245
|
-
"budgets:admin",
|
|
246
245
|
"admin"
|
|
247
246
|
];
|
|
248
247
|
z.strictObject({
|
|
@@ -1427,7 +1426,8 @@ z.object({ name: SecretNameSchema });
|
|
|
1427
1426
|
const issuerUrl = z.url().refine((value) => {
|
|
1428
1427
|
if (!URL.canParse(value)) return false;
|
|
1429
1428
|
const url = new URL(value);
|
|
1430
|
-
|
|
1429
|
+
const clusterLocal = url.protocol === "http:" && url.hostname.endsWith(".svc.cluster.local");
|
|
1430
|
+
return (url.protocol === "https:" || clusterLocal) && !url.username && !url.password && !url.search && !url.hash;
|
|
1431
1431
|
});
|
|
1432
1432
|
const IssuerConfigSchema = z.strictObject({
|
|
1433
1433
|
url: issuerUrl,
|
|
@@ -2514,7 +2514,8 @@ const TerminalSessionPageSchema = CursorPageSchema(TerminalSessionSchema);
|
|
|
2514
2514
|
//#region ../contracts/src/protocol/protocol-credentials.ts
|
|
2515
2515
|
const WorkspaceCredentialSchema = z.object({
|
|
2516
2516
|
lease_id: z.uuid(),
|
|
2517
|
-
path: z.string().regex(/^\/run\/pocketcoder\/secrets\/leases\/[A-Za-z0-9][A-Za-z0-9_
|
|
2517
|
+
path: z.string().regex(/^\/run\/pocketcoder\/secrets\/leases\/(?:sessions\/[0-9a-f-]{36}\/)?[A-Za-z0-9][A-Za-z0-9_.%-]{0,127}$/),
|
|
2518
|
+
session_id: z.uuid().optional(),
|
|
2518
2519
|
credential: z.string().min(1).max(SOURCE_CREDENTIAL_MAX_BYTES).refine((value) => !value.includes("\0")),
|
|
2519
2520
|
expires_at: z.iso.datetime(),
|
|
2520
2521
|
purpose: z.enum(["setup-issuer", "runtime-issuer"])
|
|
@@ -2532,6 +2533,10 @@ const CredentialInstalledPayload = z.object({
|
|
|
2532
2533
|
previous_lease_id: z.uuid(),
|
|
2533
2534
|
lease_id: z.uuid()
|
|
2534
2535
|
});
|
|
2536
|
+
const CredentialInstallPayload = z.object({ credentials: z.array(WorkspaceCredentialSchema).min(1).max(64) });
|
|
2537
|
+
const CredentialRemovePayload = z.object({ session_id: z.uuid() });
|
|
2538
|
+
const CredentialInstallAckPayload = z.object({ lease_ids: z.array(z.uuid()).min(1).max(64) });
|
|
2539
|
+
const CredentialRemoveAckPayload = z.object({ session_id: z.uuid() });
|
|
2535
2540
|
//#endregion
|
|
2536
2541
|
//#region ../contracts/src/protocol/protocol-stream.ts
|
|
2537
2542
|
const ProxyStreamStartPayload = z.object({
|
|
@@ -2621,7 +2626,8 @@ const EnvelopeBase = z.object({
|
|
|
2621
2626
|
z.literal(11),
|
|
2622
2627
|
z.literal(12),
|
|
2623
2628
|
z.literal(13),
|
|
2624
|
-
z.literal(14)
|
|
2629
|
+
z.literal(14),
|
|
2630
|
+
z.literal(15)
|
|
2625
2631
|
]),
|
|
2626
2632
|
workspace_id: z.uuid(),
|
|
2627
2633
|
connection_id: z.uuid(),
|
|
@@ -2760,6 +2766,14 @@ z.discriminatedUnion("type", [
|
|
|
2760
2766
|
type: z.literal("credential_installed"),
|
|
2761
2767
|
payload: CredentialInstalledPayload
|
|
2762
2768
|
}),
|
|
2769
|
+
EnvelopeBase.extend({
|
|
2770
|
+
type: z.literal("credential_install_ack"),
|
|
2771
|
+
payload: CredentialInstallAckPayload
|
|
2772
|
+
}),
|
|
2773
|
+
EnvelopeBase.extend({
|
|
2774
|
+
type: z.literal("credential_remove_ack"),
|
|
2775
|
+
payload: CredentialRemoveAckPayload
|
|
2776
|
+
}),
|
|
2763
2777
|
EnvelopeBase.extend({
|
|
2764
2778
|
type: z.literal("setup_complete"),
|
|
2765
2779
|
payload: z.object({ request_id: z.uuid() })
|
|
@@ -2939,6 +2953,14 @@ z.discriminatedUnion("type", [
|
|
|
2939
2953
|
type: z.literal("credential_installed_ack"),
|
|
2940
2954
|
payload: CredentialInstalledPayload
|
|
2941
2955
|
}),
|
|
2956
|
+
EnvelopeBase.extend({
|
|
2957
|
+
type: z.literal("credential_install"),
|
|
2958
|
+
payload: CredentialInstallPayload
|
|
2959
|
+
}),
|
|
2960
|
+
EnvelopeBase.extend({
|
|
2961
|
+
type: z.literal("credential_remove"),
|
|
2962
|
+
payload: CredentialRemovePayload
|
|
2963
|
+
}),
|
|
2942
2964
|
EnvelopeBase.extend({
|
|
2943
2965
|
type: z.literal("setup_complete_ack"),
|
|
2944
2966
|
payload: z.object({ request_id: z.uuid() })
|
|
@@ -3049,30 +3071,7 @@ z.strictObject({
|
|
|
3049
3071
|
lock: fileIdentity
|
|
3050
3072
|
});
|
|
3051
3073
|
//#endregion
|
|
3052
|
-
//#region ../contracts/src/budgets/policy.ts
|
|
3053
|
-
const BudgetPolicyWriteSchema = z.strictObject({
|
|
3054
|
-
scopeId: z.uuid(),
|
|
3055
|
-
revision: z.number().int().min(1).max(Number.MAX_SAFE_INTEGER),
|
|
3056
|
-
period: z.enum(["utc_day", "utc_month"]),
|
|
3057
|
-
limits: z.strictObject({
|
|
3058
|
-
workspaceStarts: z.number().int().min(0).max(Number.MAX_SAFE_INTEGER).nullable(),
|
|
3059
|
-
maxActiveWorkspaces: z.number().int().min(0).max(Number.MAX_SAFE_INTEGER).nullable(),
|
|
3060
|
-
maxRunningRequestsPerSession: z.literal(1),
|
|
3061
|
-
maxChatProcessesPerWorkspace: z.number().int().min(1).max(Number.MAX_SAFE_INTEGER)
|
|
3062
|
-
})
|
|
3063
|
-
});
|
|
3064
|
-
const BudgetPolicySchema = BudgetPolicyWriteSchema.extend({ effectiveAt: z.iso.datetime({ offset: true }) });
|
|
3065
|
-
//#endregion
|
|
3066
3074
|
//#region ../contracts/src/budgets/usage.ts
|
|
3067
|
-
const BudgetUsageSchema = z.strictObject({
|
|
3068
|
-
scopeId: z.uuid(),
|
|
3069
|
-
policyRevision: z.number().int().min(1).max(Number.MAX_SAFE_INTEGER),
|
|
3070
|
-
periodStart: z.iso.datetime({ offset: true }),
|
|
3071
|
-
periodEnd: z.iso.datetime({ offset: true }),
|
|
3072
|
-
workspaceStarts: z.number().int().min(0).max(Number.MAX_SAFE_INTEGER),
|
|
3073
|
-
activeWorkspaces: z.number().int().min(0).max(Number.MAX_SAFE_INTEGER),
|
|
3074
|
-
asOf: z.iso.datetime({ offset: true })
|
|
3075
|
-
});
|
|
3076
3075
|
const CleanupReceiptFieldsSchema = z.strictObject({
|
|
3077
3076
|
workspaceId: z.uuid(),
|
|
3078
3077
|
generationId: z.string().min(1).max(256),
|
|
@@ -3237,24 +3236,38 @@ const CollectionResultSchema = z.union([fields.extend({
|
|
|
3237
3236
|
});
|
|
3238
3237
|
//#endregion
|
|
3239
3238
|
//#region ../contracts/src/sessions/profile.ts
|
|
3240
|
-
const
|
|
3241
|
-
|
|
3242
|
-
|
|
3243
|
-
|
|
3244
|
-
|
|
3245
|
-
|
|
3246
|
-
|
|
3239
|
+
const ProfileNameSchema = z.string().regex(/^[A-Za-z0-9][A-Za-z0-9_.-]{0,127}$/);
|
|
3240
|
+
const ProfileConfigSchema = z.strictObject({
|
|
3241
|
+
template: z.string().min(1).max(128),
|
|
3242
|
+
templateVersion: z.string().min(1).max(128).optional(),
|
|
3243
|
+
issuer: ProfileNameSchema.optional(),
|
|
3244
|
+
placement: z.enum(["exclusive", "shared"]).default("exclusive"),
|
|
3245
|
+
limits: z.strictObject({
|
|
3246
|
+
workspacesPerOwner: z.number().int().positive().default(1),
|
|
3247
|
+
sessionsPerWorkspace: z.number().int().positive().default(1)
|
|
3248
|
+
}).default({
|
|
3249
|
+
workspacesPerOwner: 1,
|
|
3250
|
+
sessionsPerWorkspace: 1
|
|
3251
|
+
}),
|
|
3252
|
+
dispatchDeadlineSeconds: z.number().int().positive().default(600)
|
|
3253
|
+
});
|
|
3254
|
+
const SessionProfileSchema = ProfileConfigSchema.extend({
|
|
3255
|
+
name: ProfileNameSchema,
|
|
3256
|
+
templateVersion: z.string().nullable(),
|
|
3257
|
+
disabled: z.boolean()
|
|
3247
3258
|
});
|
|
3248
3259
|
const SessionCreateSchema = z.strictObject({
|
|
3249
3260
|
sessionId: z.uuid(),
|
|
3250
|
-
|
|
3251
|
-
|
|
3261
|
+
profile: ProfileNameSchema,
|
|
3262
|
+
owner: z.string().min(1).max(128),
|
|
3263
|
+
group: z.string().min(1).max(128).optional()
|
|
3252
3264
|
});
|
|
3253
3265
|
const SessionSchema = z.strictObject({
|
|
3254
3266
|
sessionId: z.uuid(),
|
|
3255
|
-
|
|
3256
|
-
|
|
3257
|
-
|
|
3267
|
+
profile: ProfileNameSchema,
|
|
3268
|
+
owner: z.string().min(1).max(128),
|
|
3269
|
+
group: z.string().min(1).max(128),
|
|
3270
|
+
revision: z.number().int().positive(),
|
|
3258
3271
|
state: z.enum([
|
|
3259
3272
|
"provisioning",
|
|
3260
3273
|
"ready",
|
|
@@ -3271,8 +3284,7 @@ const SessionSchema = z.strictObject({
|
|
|
3271
3284
|
const RequestInputSchema = z.strictObject({
|
|
3272
3285
|
requestId: z.uuid(),
|
|
3273
3286
|
message: z.string().min(1).max(262144).refine((value) => value.isWellFormed(), "Message must contain valid Unicode").refine((value) => new TextEncoder().encode(value).length <= 262144, "Message exceeds 256 KiB UTF-8"),
|
|
3274
|
-
attachments: z.array(
|
|
3275
|
-
dispatchDeadline: z.iso.datetime({ offset: true })
|
|
3287
|
+
attachments: z.array(z.uuid()).max(MAX_SESSION_FILE_REFERENCES).default([])
|
|
3276
3288
|
});
|
|
3277
3289
|
const RequestFieldsSchema = z.strictObject({
|
|
3278
3290
|
sessionId: z.uuid(),
|
|
@@ -3327,16 +3339,13 @@ const RequestSchema = z.union([RequestFieldsSchema.extend({
|
|
|
3327
3339
|
message: "Collection owner mismatch"
|
|
3328
3340
|
});
|
|
3329
3341
|
});
|
|
3330
|
-
const CancelCommandSchema = z.strictObject({ cancelId: z.uuid() });
|
|
3331
3342
|
const CancelReceiptFieldsSchema = z.strictObject({
|
|
3332
3343
|
sessionId: z.uuid(),
|
|
3333
3344
|
requestId: z.uuid().nullable(),
|
|
3334
|
-
cancelId: z.uuid(),
|
|
3335
3345
|
scope: z.enum(["request", "session"]),
|
|
3336
3346
|
state: z.enum(["pending", "completed"]),
|
|
3337
3347
|
acceptedAt: z.iso.datetime({ offset: true }),
|
|
3338
|
-
completedAt: z.iso.datetime({ offset: true }).nullable()
|
|
3339
|
-
cancelDeadline: z.iso.datetime({ offset: true })
|
|
3348
|
+
completedAt: z.iso.datetime({ offset: true }).nullable()
|
|
3340
3349
|
});
|
|
3341
3350
|
const CancelReceiptSchema = z.union([CancelReceiptFieldsSchema.extend({
|
|
3342
3351
|
scope: z.literal("request"),
|
|
@@ -3352,6 +3361,32 @@ const CancelReceiptSchema = z.union([CancelReceiptFieldsSchema.extend({
|
|
|
3352
3361
|
});
|
|
3353
3362
|
});
|
|
3354
3363
|
//#endregion
|
|
3364
|
+
//#region ../contracts/src/sessions/conversation.ts
|
|
3365
|
+
const SessionMessageSchema = z.object({
|
|
3366
|
+
messageId: z.string(),
|
|
3367
|
+
requestId: z.uuid(),
|
|
3368
|
+
turnId: z.uuid(),
|
|
3369
|
+
role: z.enum([
|
|
3370
|
+
"user",
|
|
3371
|
+
"assistant",
|
|
3372
|
+
"tool",
|
|
3373
|
+
"system"
|
|
3374
|
+
]),
|
|
3375
|
+
parts: z.array(ConversationPartSchema),
|
|
3376
|
+
final: z.boolean(),
|
|
3377
|
+
occurredAt: z.iso.datetime()
|
|
3378
|
+
});
|
|
3379
|
+
const SessionConversationSchema = z.object({
|
|
3380
|
+
session: SessionSchema.pick({
|
|
3381
|
+
state: true,
|
|
3382
|
+
reasonCode: true
|
|
3383
|
+
}),
|
|
3384
|
+
requests: z.array(RequestSchema),
|
|
3385
|
+
messages: z.array(SessionMessageSchema),
|
|
3386
|
+
cursor: z.string(),
|
|
3387
|
+
reset: z.boolean()
|
|
3388
|
+
});
|
|
3389
|
+
//#endregion
|
|
3355
3390
|
//#region ../contracts/src/sessions/event.ts
|
|
3356
3391
|
const RuntimeEventFieldsSchema = z.strictObject({
|
|
3357
3392
|
eventId: z.uuid(),
|
|
@@ -3420,25 +3455,27 @@ const ErrorSchema = z.strictObject({ error: z.strictObject({
|
|
|
3420
3455
|
}) });
|
|
3421
3456
|
//#endregion
|
|
3422
3457
|
//#region ../contracts/src/sessions/fingerprint.ts
|
|
3423
|
-
const LogicalRequestInputSchema = RequestInputSchema.extend({
|
|
3424
|
-
sessionId: z.uuid(),
|
|
3425
|
-
profileId: z.uuid(),
|
|
3426
|
-
profileRevision: z.number().int().positive().max(Number.MAX_SAFE_INTEGER)
|
|
3427
|
-
}).superRefine((input, ctx) => {
|
|
3428
|
-
for (const [index, attachment] of input.attachments.entries()) for (const field of ["name", "mediaType"]) if (!attachment[field].isWellFormed()) ctx.addIssue({
|
|
3429
|
-
code: "custom",
|
|
3430
|
-
path: [
|
|
3431
|
-
"attachments",
|
|
3432
|
-
index,
|
|
3433
|
-
field
|
|
3434
|
-
],
|
|
3435
|
-
message: "Invalid Unicode"
|
|
3436
|
-
});
|
|
3437
|
-
});
|
|
3438
3458
|
function fingerprintRequest(input) {
|
|
3439
|
-
|
|
3459
|
+
const { message, attachments } = RequestInputSchema.parse(input);
|
|
3460
|
+
return digestOf({
|
|
3461
|
+
message,
|
|
3462
|
+
attachments
|
|
3463
|
+
});
|
|
3440
3464
|
}
|
|
3441
3465
|
//#endregion
|
|
3466
|
+
//#region ../contracts/src/sessions/issuer.ts
|
|
3467
|
+
const IssuerUrlSchema = z.url().refine((value) => {
|
|
3468
|
+
const url = new URL(value);
|
|
3469
|
+
const local = url.protocol === "http:" && url.hostname.endsWith(".svc.cluster.local");
|
|
3470
|
+
return (url.protocol === "https:" || local) && !url.username && !url.password && !url.search && !url.hash;
|
|
3471
|
+
});
|
|
3472
|
+
const SessionIssuerSchema = z.strictObject({
|
|
3473
|
+
url: IssuerUrlSchema,
|
|
3474
|
+
tokenFile: z.string().startsWith("/"),
|
|
3475
|
+
policy: z.record(z.string(), z.json()).default({}),
|
|
3476
|
+
revoke: z.boolean().default(false)
|
|
3477
|
+
});
|
|
3478
|
+
//#endregion
|
|
3442
3479
|
//#region ../contracts/src/sessions/pages.ts
|
|
3443
3480
|
const ManagedHistoryQuerySchema = z.strictObject({
|
|
3444
3481
|
cursor: z.string().min(1).max(4096).optional(),
|
|
@@ -3455,34 +3492,23 @@ const ManagedExportPageSchema = z.strictObject({
|
|
|
3455
3492
|
});
|
|
3456
3493
|
//#endregion
|
|
3457
3494
|
//#region ../contracts/src/sessions/placement.ts
|
|
3458
|
-
function managedPlacement(principalId,
|
|
3459
|
-
const
|
|
3460
|
-
const mode = profile.credentialBindingId === null ? "shared" : "exclusive";
|
|
3495
|
+
function managedPlacement(principalId, session, profile) {
|
|
3496
|
+
const mode = profile.placement;
|
|
3461
3497
|
return {
|
|
3462
3498
|
mode,
|
|
3463
3499
|
key: digestOf({
|
|
3464
3500
|
principalId,
|
|
3465
|
-
profile,
|
|
3466
|
-
|
|
3501
|
+
profile: session.profile,
|
|
3502
|
+
owner: session.owner,
|
|
3503
|
+
group: session.group,
|
|
3504
|
+
template: profile.template,
|
|
3505
|
+
templateVersion: profile.templateVersion,
|
|
3506
|
+
sessionId: mode === "exclusive" ? session.sessionId : null
|
|
3467
3507
|
})
|
|
3468
3508
|
};
|
|
3469
3509
|
}
|
|
3470
3510
|
const MANAGED_SESSION_METADATA = "pocketcoder.managed-session";
|
|
3471
3511
|
//#endregion
|
|
3472
|
-
//#region ../contracts/src/sessions/provisioning.ts
|
|
3473
|
-
const BudgetScopeGrantSchema = z.strictObject({
|
|
3474
|
-
principalId: z.uuid(),
|
|
3475
|
-
installation: z.boolean()
|
|
3476
|
-
});
|
|
3477
|
-
const CredentialBindingSchema = z.strictObject({
|
|
3478
|
-
bindingId: z.uuid(),
|
|
3479
|
-
principalId: z.uuid(),
|
|
3480
|
-
secretName: z.string().min(1).max(128),
|
|
3481
|
-
secretVersionId: z.uuid().optional(),
|
|
3482
|
-
slots: z.array(z.string().min(1).max(128)).min(1).max(100),
|
|
3483
|
-
authorityExpiresAt: z.iso.datetime({ offset: true })
|
|
3484
|
-
});
|
|
3485
|
-
//#endregion
|
|
3486
3512
|
//#region ../contracts/src/sessions/states.ts
|
|
3487
3513
|
const requestTransitions = {
|
|
3488
3514
|
accepted: [
|
|
@@ -3528,77 +3554,48 @@ const ManagedQueueLimitsSchema = z.strictObject({
|
|
|
3528
3554
|
bytes: z.number().int().positive().max(Number.MAX_SAFE_INTEGER)
|
|
3529
3555
|
});
|
|
3530
3556
|
//#endregion
|
|
3531
|
-
//#region ../contracts/src/sessions/schemas.ts
|
|
3532
|
-
const MANAGED_CONTRACT_REVISION = "pocketcoder.managed/v1";
|
|
3533
|
-
const managedSchemas = {
|
|
3534
|
-
ExecutionProfile: ExecutionProfileSchema,
|
|
3535
|
-
BudgetScopeGrant: BudgetScopeGrantSchema,
|
|
3536
|
-
CredentialBinding: CredentialBindingSchema,
|
|
3537
|
-
SessionCreate: SessionCreateSchema,
|
|
3538
|
-
Session: SessionSchema,
|
|
3539
|
-
InputReference: InputReferenceSchema,
|
|
3540
|
-
InputUpload: InputUploadSchema,
|
|
3541
|
-
InputObject: InputObjectSchema,
|
|
3542
|
-
ExportObject: ExportObjectSchema,
|
|
3543
|
-
CollectionResult: CollectionResultSchema,
|
|
3544
|
-
RequestInput: RequestInputSchema,
|
|
3545
|
-
Request: RequestSchema,
|
|
3546
|
-
CancelCommand: CancelCommandSchema,
|
|
3547
|
-
CancelReceipt: CancelReceiptSchema,
|
|
3548
|
-
RuntimeEvent: RuntimeEventSchema,
|
|
3549
|
-
Error: ErrorSchema,
|
|
3550
|
-
WireError: ErrorEnvelopeSchema,
|
|
3551
|
-
BudgetPolicy: BudgetPolicySchema,
|
|
3552
|
-
BudgetPolicyWrite: BudgetPolicyWriteSchema,
|
|
3553
|
-
BudgetUsage: BudgetUsageSchema,
|
|
3554
|
-
CleanupReceipt: CleanupReceiptSchema,
|
|
3555
|
-
HistoryPage: ManagedHistoryPageSchema,
|
|
3556
|
-
OpenTurns: z.object({ turns: z.array(ConversationLiveEventSchema) }),
|
|
3557
|
-
ExportPage: ManagedExportPageSchema,
|
|
3558
|
-
ServiceStart: ServiceStartSchema,
|
|
3559
|
-
ServiceReceipt: ServiceReceiptSchema,
|
|
3560
|
-
LifetimeExtension: LifetimeExtensionSchema,
|
|
3561
|
-
LifetimeReceipt: LifetimeReceiptSchema,
|
|
3562
|
-
QueueLimits: ManagedQueueLimitsSchema
|
|
3563
|
-
};
|
|
3564
|
-
//#endregion
|
|
3565
3557
|
//#region ../contracts/src/sessions/index.ts
|
|
3566
3558
|
var sessions_exports = /* @__PURE__ */ __exportAll({
|
|
3567
|
-
BudgetPolicySchema: () => BudgetPolicySchema,
|
|
3568
|
-
BudgetPolicyWriteSchema: () => BudgetPolicyWriteSchema,
|
|
3569
|
-
BudgetUsageSchema: () => BudgetUsageSchema,
|
|
3570
|
-
CancelCommandSchema: () => CancelCommandSchema,
|
|
3571
3559
|
CancelReceiptSchema: () => CancelReceiptSchema,
|
|
3572
3560
|
CleanupReceiptSchema: () => CleanupReceiptSchema,
|
|
3573
3561
|
CollectionResultSchema: () => CollectionResultSchema,
|
|
3574
3562
|
ErrorSchema: () => ErrorSchema,
|
|
3575
|
-
ExecutionProfileSchema: () => ExecutionProfileSchema,
|
|
3576
3563
|
ExportObjectSchema: () => ExportObjectSchema,
|
|
3577
3564
|
InputObjectSchema: () => InputObjectSchema,
|
|
3578
3565
|
InputReferenceSchema: () => InputReferenceSchema,
|
|
3579
3566
|
InputUploadSchema: () => InputUploadSchema,
|
|
3567
|
+
IssuerUrlSchema: () => IssuerUrlSchema,
|
|
3580
3568
|
LifetimeExtensionSchema: () => LifetimeExtensionSchema,
|
|
3581
3569
|
LifetimeReceiptSchema: () => LifetimeReceiptSchema,
|
|
3582
|
-
LogicalRequestInputSchema: () => LogicalRequestInputSchema,
|
|
3583
|
-
MANAGED_CONTRACT_REVISION: () => MANAGED_CONTRACT_REVISION,
|
|
3584
3570
|
MANAGED_SESSION_METADATA: () => MANAGED_SESSION_METADATA,
|
|
3585
3571
|
MAX_SESSION_FILE_REFERENCES: () => MAX_SESSION_FILE_REFERENCES,
|
|
3586
3572
|
ManagedExportPageSchema: () => ManagedExportPageSchema,
|
|
3587
3573
|
ManagedHistoryPageSchema: () => ManagedHistoryPageSchema,
|
|
3588
3574
|
ManagedHistoryQuerySchema: () => ManagedHistoryQuerySchema,
|
|
3589
3575
|
ManagedQueueLimitsSchema: () => ManagedQueueLimitsSchema,
|
|
3576
|
+
ProfileConfigSchema: () => ProfileConfigSchema,
|
|
3577
|
+
ProfileNameSchema: () => ProfileNameSchema,
|
|
3590
3578
|
RequestInputSchema: () => RequestInputSchema,
|
|
3591
3579
|
RequestSchema: () => RequestSchema,
|
|
3592
3580
|
RuntimeEventSchema: () => RuntimeEventSchema,
|
|
3593
3581
|
ServiceReceiptSchema: () => ServiceReceiptSchema,
|
|
3594
3582
|
ServiceStartSchema: () => ServiceStartSchema,
|
|
3583
|
+
SessionConversationSchema: () => SessionConversationSchema,
|
|
3595
3584
|
SessionCreateSchema: () => SessionCreateSchema,
|
|
3585
|
+
SessionIssuerSchema: () => SessionIssuerSchema,
|
|
3586
|
+
SessionMessageSchema: () => SessionMessageSchema,
|
|
3587
|
+
SessionProfileSchema: () => SessionProfileSchema,
|
|
3596
3588
|
SessionSchema: () => SessionSchema,
|
|
3597
3589
|
canTransitionRequest: () => canTransitionRequest,
|
|
3598
3590
|
canTransitionSession: () => canTransitionSession,
|
|
3599
3591
|
fingerprintRequest: () => fingerprintRequest,
|
|
3600
|
-
managedPlacement: () => managedPlacement
|
|
3601
|
-
|
|
3592
|
+
managedPlacement: () => managedPlacement
|
|
3593
|
+
});
|
|
3594
|
+
//#endregion
|
|
3595
|
+
//#region ../contracts/src/sessions/history-seed.ts
|
|
3596
|
+
const PriorMessageSchema = z.object({
|
|
3597
|
+
role: z.enum(["user", "assistant"]),
|
|
3598
|
+
content: z.string()
|
|
3602
3599
|
});
|
|
3603
3600
|
//#endregion
|
|
3604
3601
|
//#region ../contracts/src/templates/session-template.ts
|
|
@@ -3651,7 +3648,7 @@ function sessionTemplate(input) {
|
|
|
3651
3648
|
].map((action) => ({
|
|
3652
3649
|
method: "POST",
|
|
3653
3650
|
path: `/executions/${action}`,
|
|
3654
|
-
maxRequestBytes:
|
|
3651
|
+
maxRequestBytes: 2097152,
|
|
3655
3652
|
maxResponseBytes: 8388608,
|
|
3656
3653
|
deadlineSeconds: 30
|
|
3657
3654
|
}))
|
|
@@ -3720,6 +3717,7 @@ const ExecutionPhaseSchema = z.enum([
|
|
|
3720
3717
|
]);
|
|
3721
3718
|
const ExecutionRecordSchema = z.strictObject({
|
|
3722
3719
|
acceptance: WorkloadAcceptanceSchema,
|
|
3720
|
+
priorMessages: z.array(PriorMessageSchema).optional(),
|
|
3723
3721
|
conversationIdentity: ConversationRequestIdentitySchema.nullable(),
|
|
3724
3722
|
outcome: JsonValueSchema.nullable(),
|
|
3725
3723
|
acceptedAt: z.iso.datetime(),
|
|
@@ -3852,50 +3850,6 @@ var AttachmentsApi = class {
|
|
|
3852
3850
|
}
|
|
3853
3851
|
};
|
|
3854
3852
|
//#endregion
|
|
3855
|
-
//#region src/resources/budgets/budgets.ts
|
|
3856
|
-
const scopePath = (scopeId) => `/v1/budget-scopes/${encodeURIComponent(scopeId)}`;
|
|
3857
|
-
var ManagedAuthorityApi = class {
|
|
3858
|
-
transport;
|
|
3859
|
-
constructor(transport) {
|
|
3860
|
-
this.transport = transport;
|
|
3861
|
-
}
|
|
3862
|
-
async grantScope(scopeId, grant, options = {}) {
|
|
3863
|
-
await this.transport.request(`${scopePath(scopeId)}/grant`, z.undefined(), {
|
|
3864
|
-
...options,
|
|
3865
|
-
method: "PUT",
|
|
3866
|
-
body: JSON.stringify(managedSchemas.BudgetScopeGrant.parse(grant))
|
|
3867
|
-
});
|
|
3868
|
-
}
|
|
3869
|
-
putPolicy(policy, expectedRevision, options = {}) {
|
|
3870
|
-
return this.transport.request(`${scopePath(policy.scopeId)}/policy`, BudgetPolicySchema, {
|
|
3871
|
-
...options,
|
|
3872
|
-
method: "PUT",
|
|
3873
|
-
body: JSON.stringify(BudgetPolicyWriteSchema.parse(policy)),
|
|
3874
|
-
headers: expectedRevision === null ? { "if-none-match": "*" } : { "if-match": `"${expectedRevision}"` }
|
|
3875
|
-
});
|
|
3876
|
-
}
|
|
3877
|
-
getPolicy(scopeId, options = {}) {
|
|
3878
|
-
return this.transport.request(`${scopePath(scopeId)}/policy`, BudgetPolicySchema, options);
|
|
3879
|
-
}
|
|
3880
|
-
usage(scopeId, options = {}) {
|
|
3881
|
-
return this.transport.request(`${scopePath(scopeId)}/usage`, BudgetUsageSchema, options);
|
|
3882
|
-
}
|
|
3883
|
-
putProfile(principalId, profile, options = {}) {
|
|
3884
|
-
return this.transport.request(`/v1/execution-profiles/${encodeURIComponent(profile.profileId)}/revisions/${profile.revision}?principalId=${encodeURIComponent(principalId)}`, ExecutionProfileSchema, {
|
|
3885
|
-
...options,
|
|
3886
|
-
method: "PUT",
|
|
3887
|
-
body: JSON.stringify(ExecutionProfileSchema.parse(profile))
|
|
3888
|
-
});
|
|
3889
|
-
}
|
|
3890
|
-
async putCredentialBinding(binding, options = {}) {
|
|
3891
|
-
await this.transport.request(`/v1/credential-bindings/${encodeURIComponent(binding.bindingId)}`, z.undefined(), {
|
|
3892
|
-
...options,
|
|
3893
|
-
method: "PUT",
|
|
3894
|
-
body: JSON.stringify(managedSchemas.CredentialBinding.parse(binding))
|
|
3895
|
-
});
|
|
3896
|
-
}
|
|
3897
|
-
};
|
|
3898
|
-
//#endregion
|
|
3899
3853
|
//#region src/transport/common.ts
|
|
3900
3854
|
function queryString(values) {
|
|
3901
3855
|
const params = new URLSearchParams();
|
|
@@ -4378,6 +4332,21 @@ var SessionsApi = class {
|
|
|
4378
4332
|
constructor(transport) {
|
|
4379
4333
|
this.transport = transport;
|
|
4380
4334
|
}
|
|
4335
|
+
list(query = {}, options = {}) {
|
|
4336
|
+
return this.transport.request(`/v1/sessions?${queryString(query)}`, z.array(SessionSchema.extend({ activeRequestId: z.uuid().nullable() })), options);
|
|
4337
|
+
}
|
|
4338
|
+
cancel(sessionId, options = {}) {
|
|
4339
|
+
return this.transport.request(`${sessionPath(sessionId)}/cancel`, CancelReceiptSchema, {
|
|
4340
|
+
...options,
|
|
4341
|
+
method: "POST"
|
|
4342
|
+
});
|
|
4343
|
+
}
|
|
4344
|
+
conversation(sessionId, query = {}, options = {}) {
|
|
4345
|
+
return this.transport.request(`${sessionPath(sessionId)}/conversation?${queryString(query)}`, SessionConversationSchema, options);
|
|
4346
|
+
}
|
|
4347
|
+
upload(sessionId, file, options = {}) {
|
|
4348
|
+
return new SessionFilesApi(this.transport).put(sessionId, file, options);
|
|
4349
|
+
}
|
|
4381
4350
|
create(input, options = {}) {
|
|
4382
4351
|
return this.transport.request("/v1/sessions", SessionSchema, {
|
|
4383
4352
|
...options,
|
|
@@ -4394,11 +4363,10 @@ var SessionsApi = class {
|
|
|
4394
4363
|
method: "POST"
|
|
4395
4364
|
});
|
|
4396
4365
|
}
|
|
4397
|
-
close(sessionId,
|
|
4366
|
+
close(sessionId, options = {}) {
|
|
4398
4367
|
return this.transport.request(`${sessionPath(sessionId)}/close`, CancelReceiptSchema, {
|
|
4399
4368
|
...options,
|
|
4400
|
-
method: "POST"
|
|
4401
|
-
body: JSON.stringify(CancelCommandSchema.parse(command))
|
|
4369
|
+
method: "POST"
|
|
4402
4370
|
});
|
|
4403
4371
|
}
|
|
4404
4372
|
history(sessionId, query = {}, options = {}) {
|
|
@@ -4428,9 +4396,6 @@ var SessionsApi = class {
|
|
|
4428
4396
|
events(sessionId, options = {}) {
|
|
4429
4397
|
return sessionEvents(this.transport, sessionId, options);
|
|
4430
4398
|
}
|
|
4431
|
-
open(sessionId, options = {}) {
|
|
4432
|
-
return this.transport.request(`${sessionPath(sessionId)}/conversation/open`, z.object({ turns: z.array(ConversationLiveEventSchema) }), options);
|
|
4433
|
-
}
|
|
4434
4399
|
openPreview(sessionId, name, options = {}) {
|
|
4435
4400
|
return this.transport.request(`${sessionPath(sessionId)}/previews/${encodeURIComponent(name)}`, SessionPreviewSchema, {
|
|
4436
4401
|
method: "POST",
|
|
@@ -4449,34 +4414,17 @@ var SessionFilesApi = class {
|
|
|
4449
4414
|
constructor(transport) {
|
|
4450
4415
|
this.transport = transport;
|
|
4451
4416
|
}
|
|
4452
|
-
|
|
4453
|
-
return this.transport.request(`${sessionPath(sessionId)}/inputs`, InputObjectSchema, {
|
|
4454
|
-
...options,
|
|
4455
|
-
method: "POST",
|
|
4456
|
-
body: JSON.stringify(InputUploadSchema.parse(input))
|
|
4457
|
-
});
|
|
4458
|
-
}
|
|
4459
|
-
upload(sessionId, inputId, bytes, options = {}) {
|
|
4460
|
-
return this.transport.request(`${sessionPath(sessionId)}/inputs/${encodeURIComponent(inputId)}/content`, InputObjectSchema, {
|
|
4417
|
+
put(sessionId, file, options = {}) {
|
|
4418
|
+
return this.transport.request(`${sessionPath(sessionId)}/inputs/${encodeURIComponent(file.inputId)}`, InputObjectSchema, {
|
|
4461
4419
|
...options,
|
|
4462
4420
|
method: "PUT",
|
|
4463
|
-
body: bytes,
|
|
4464
|
-
headers: {
|
|
4421
|
+
body: file.bytes,
|
|
4422
|
+
headers: {
|
|
4423
|
+
"content-type": file.mediaType,
|
|
4424
|
+
"content-disposition": contentDisposition(file.name)
|
|
4425
|
+
}
|
|
4465
4426
|
});
|
|
4466
4427
|
}
|
|
4467
|
-
async put(sessionId, file, options = {}) {
|
|
4468
|
-
const digest = new Uint8Array(await crypto.subtle.digest("SHA-256", file.bytes));
|
|
4469
|
-
const sha256 = `sha256:${Array.from(digest, (byte) => byte.toString(16).padStart(2, "0")).join("")}`;
|
|
4470
|
-
const registered = await this.register(sessionId, {
|
|
4471
|
-
inputId: file.inputId,
|
|
4472
|
-
name: file.name,
|
|
4473
|
-
mediaType: file.mediaType,
|
|
4474
|
-
sizeBytes: file.bytes.byteLength,
|
|
4475
|
-
sha256
|
|
4476
|
-
}, options);
|
|
4477
|
-
if (registered.state === "ready") return registered;
|
|
4478
|
-
return this.upload(sessionId, file.inputId, file.bytes, options);
|
|
4479
|
-
}
|
|
4480
4428
|
get(sessionId, inputId, options = {}) {
|
|
4481
4429
|
return this.transport.request(`${sessionPath(sessionId)}/inputs/${encodeURIComponent(inputId)}`, InputObjectSchema, options);
|
|
4482
4430
|
}
|
|
@@ -4493,6 +4441,17 @@ var SessionFilesApi = class {
|
|
|
4493
4441
|
}
|
|
4494
4442
|
};
|
|
4495
4443
|
//#endregion
|
|
4444
|
+
//#region src/resources/sessions/profiles.ts
|
|
4445
|
+
var SessionProfilesApi = class {
|
|
4446
|
+
transport;
|
|
4447
|
+
constructor(transport) {
|
|
4448
|
+
this.transport = transport;
|
|
4449
|
+
}
|
|
4450
|
+
get(name, options = {}) {
|
|
4451
|
+
return this.transport.request(`/v1/session-profiles/${encodeURIComponent(name)}`, SessionProfileSchema, options);
|
|
4452
|
+
}
|
|
4453
|
+
};
|
|
4454
|
+
//#endregion
|
|
4496
4455
|
//#region src/resources/sessions/requests.ts
|
|
4497
4456
|
const requestPath = (sessionId, requestId) => `${sessionPath(sessionId)}/requests/${encodeURIComponent(requestId)}`;
|
|
4498
4457
|
var SessionRequestsApi = class {
|
|
@@ -4510,11 +4469,10 @@ var SessionRequestsApi = class {
|
|
|
4510
4469
|
get(sessionId, requestId, options = {}) {
|
|
4511
4470
|
return this.transport.request(requestPath(sessionId, requestId), RequestSchema, options);
|
|
4512
4471
|
}
|
|
4513
|
-
cancel(sessionId, requestId,
|
|
4472
|
+
cancel(sessionId, requestId, options = {}) {
|
|
4514
4473
|
return this.transport.request(`${requestPath(sessionId, requestId)}/cancel`, CancelReceiptSchema, {
|
|
4515
4474
|
...options,
|
|
4516
|
-
method: "POST"
|
|
4517
|
-
body: JSON.stringify(CancelCommandSchema.parse(command))
|
|
4475
|
+
method: "POST"
|
|
4518
4476
|
});
|
|
4519
4477
|
}
|
|
4520
4478
|
collection(sessionId, requestId, options = {}) {
|
|
@@ -4908,7 +4866,7 @@ var PocketCoderClient = class {
|
|
|
4908
4866
|
sessions;
|
|
4909
4867
|
requests;
|
|
4910
4868
|
files;
|
|
4911
|
-
|
|
4869
|
+
profiles;
|
|
4912
4870
|
constructor(config, fetchImpl = fetch) {
|
|
4913
4871
|
this.transport = new PocketCoderTransport(config, fetchImpl);
|
|
4914
4872
|
this.secrets = new SecretsApi(this.transport);
|
|
@@ -4932,7 +4890,7 @@ var PocketCoderClient = class {
|
|
|
4932
4890
|
this.sessions = new SessionsApi(this.transport);
|
|
4933
4891
|
this.requests = new SessionRequestsApi(this.transport);
|
|
4934
4892
|
this.files = new SessionFilesApi(this.transport);
|
|
4935
|
-
this.
|
|
4893
|
+
this.profiles = new SessionProfilesApi(this.transport);
|
|
4936
4894
|
}
|
|
4937
4895
|
raw(path, init = {}) {
|
|
4938
4896
|
return this.transport.raw(path, init);
|
|
@@ -5083,4 +5041,4 @@ var WorkspaceTurnResolver = class {
|
|
|
5083
5041
|
}
|
|
5084
5042
|
};
|
|
5085
5043
|
//#endregion
|
|
5086
|
-
export { AdministrationApi, AttachmentsApi, CheckpointsApi, ConversationGoneError, ConversationsApi, KeysApi, LogsApi,
|
|
5044
|
+
export { AdministrationApi, AttachmentsApi, CheckpointsApi, ConversationGoneError, ConversationsApi, KeysApi, LogsApi, NetworkEventsApi, OperationsApi, OutputsApi, PocketCoderClient, PocketCoderError, PrincipalsApi, RecoveryApi, SecretsApi, SessionFilesApi, SessionRequestsApi, SessionsApi, TERMINAL_WORKSPACE_STATES, TemplatesApi, TerminalConnection, TerminalsApi, WorkspaceRequestsApi, WorkspaceTerminalError, WorkspaceTurnResolutionError, WorkspaceTurnResolver, WorkspacesApi, isPocketCoderErrorCode, sessions_exports as managed, sessionTemplate };
|
package/package.json
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
"type:library"
|
|
7
7
|
]
|
|
8
8
|
},
|
|
9
|
-
"version": "0.
|
|
9
|
+
"version": "0.11.0",
|
|
10
10
|
"private": false,
|
|
11
11
|
"description": "Runtime-validated TypeScript client for the PocketCoder control plane.",
|
|
12
12
|
"type": "module",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
},
|
|
36
36
|
"scripts": {
|
|
37
37
|
"build": "tsdown",
|
|
38
|
-
"test": "bun --no-env-file test",
|
|
38
|
+
"test": "bun --no-env-file test --timeout 10000",
|
|
39
39
|
"typecheck": "tsc --project ./tsconfig.json --noEmit"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|