@byok-sdk/server 0.6.1 → 0.7.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/dist/index.js CHANGED
@@ -5,7 +5,7 @@ import { mkdir, writeFile, readFile } from 'fs/promises';
5
5
  import { mkdtempSync, mkdirSync, existsSync, chmodSync } from 'fs';
6
6
  import { tmpdir } from 'os';
7
7
  import path, { dirname } from 'path';
8
- import { CAPABILITY_FLAGS, byokBlobContentPath, canTransition, PROTOCOL_VERSION, encodeEnvelope, DAEMON_TO_SERVER_TYPES, AGENT_EGRESS_POLICY_CAPABILITY, AGENT_EGRESS_RELIABLE_ACK_CAPABILITY, AgentRefSchema, AgentEgressPolicySchema, DispatchSelectionSchema, RequiredToolsetsSchema, AgentContentReadPayloadSchema, createEnvelope, TASK_STATES, BYOK_PAIR_PATH, PairRequestSchema, BYOK_CHALLENGE_PATH, ChallengeRequestSchema, BYOK_TOKEN_PATH, TokenRequestSchema, BYOK_BLOBS_PATH, CreateBlobRequestSchema, BYOK_BLOB_FINALIZE_ROUTE, BYOK_BLOB_URL_ROUTE, BYOK_BLOB_CONTENT_ROUTE, BYOK_EVENTS_PATH, BYOK_MESSAGES_PATH, MessagesSendRequestSchema, AGENT_CONTENT_ARTIFACT_READ_CAPABILITY, AGENT_CONTENT_TRANSCRIPT_READ_CAPABILITY, AGENT_CONTENT_WORKSPACE_READ_CAPABILITY, decodeEnvelope, BYOK_WS_PATH } from '@byok-sdk/protocol';
8
+ import { CAPABILITY_FLAGS, byokBlobContentPath, canTransition, PROTOCOL_VERSION, encodeEnvelope, DAEMON_TO_SERVER_TYPES, AGENT_EGRESS_POLICY_CAPABILITY, AGENT_EGRESS_RELIABLE_ACK_CAPABILITY, AgentRefSchema, AgentEgressPolicySchema, DispatchSelectionSchema, RequiredToolsetsSchema, AgentContentReadPayloadSchema, createEnvelope, TASK_STATES, BYOK_PAIR_PATH, PairRequestSchema, PairResponseSchema, BYOK_CHALLENGE_PATH, ChallengeRequestSchema, BYOK_TOKEN_PATH, TokenRequestSchema, BYOK_BLOBS_PATH, CreateBlobRequestSchema, BYOK_BLOB_FINALIZE_ROUTE, BYOK_BLOB_URL_ROUTE, BYOK_BLOB_CONTENT_ROUTE, BYOK_EVENTS_PATH, BYOK_MESSAGES_PATH, MessagesSendRequestSchema, AGENT_CONTENT_ARTIFACT_READ_CAPABILITY, AGENT_CONTENT_TRANSCRIPT_READ_CAPABILITY, AGENT_CONTENT_WORKSPACE_READ_CAPABILITY, PairResponseTenantIdSchema, decodeEnvelope, BYOK_WS_PATH } from '@byok-sdk/protocol';
9
9
  import { Hono } from 'hono';
10
10
  import { WebSocketServer } from 'ws';
11
11
  import { createRequire } from 'module';
@@ -266,8 +266,6 @@ function generateDeviceId() {
266
266
  function generateTaskId() {
267
267
  return `task_${randomUUID()}`;
268
268
  }
269
-
270
- // src/pairing.ts
271
269
  var PAIRING_CODE_TTL_MS = 10 * 60 * 1e3;
272
270
  var PairingCodeInvalidError = class extends Error {
273
271
  constructor(reason) {
@@ -320,13 +318,14 @@ function validatePairingCodeClaims(claims) {
320
318
  throw new TypeError("createPairingCode requires { tenantId, productId } claims");
321
319
  }
322
320
  const { tenantId, productId } = claims;
323
- if (typeof tenantId !== "string" || tenantId.length === 0) {
324
- throw new TypeError("createPairingCode requires a non-empty tenantId");
321
+ const tenantResult = PairResponseTenantIdSchema.safeParse(tenantId);
322
+ if (!tenantResult.success) {
323
+ throw new TypeError("createPairingCode requires a valid bounded tenantId");
325
324
  }
326
325
  if (typeof productId !== "string" || productId.length === 0) {
327
326
  throw new TypeError("createPairingCode requires a non-empty productId");
328
327
  }
329
- return { tenantId, productId };
328
+ return { tenantId: tenantResult.data, productId };
330
329
  }
331
330
 
332
331
  // src/http.ts
@@ -366,12 +365,21 @@ function buildHonoApp(deps) {
366
365
  deviceName,
367
366
  devicePublicKey
368
367
  });
368
+ const device = deps.devices.get(claims.tenantId, deviceId);
369
+ if (device === void 0) {
370
+ throw new Error("paired device row was not persisted");
371
+ }
369
372
  const { accessToken, expiresAt } = await mintAccessToken(deps.tokenSigner, {
370
- deviceId,
371
- tenantId: claims.tenantId,
372
- productId: claims.productId
373
+ deviceId: device.deviceId,
374
+ tenantId: device.tenantId,
375
+ productId: device.productId
376
+ });
377
+ const response = PairResponseSchema.parse({
378
+ deviceId: device.deviceId,
379
+ accessToken,
380
+ refreshHint: expiresAt,
381
+ tenantId: device.tenantId
373
382
  });
374
- const response = { deviceId, accessToken, refreshHint: expiresAt };
375
383
  return c.json(response, 200);
376
384
  });
377
385
  app.post(BYOK_CHALLENGE_PATH, async (c) => {