@alva-ai/toolkit 0.28.0 → 0.28.1-beta.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
@@ -3246,7 +3246,6 @@ var MarketsResource = class {
3246
3246
  // src/resources/schedules.ts
3247
3247
  var SCHEDULE_FIELDS = `
3248
3248
  id
3249
- channel { id }
3250
3249
  name
3251
3250
  rule { kind atMs everyIntervalSeconds cronExpression cronTimezone }
3252
3251
  bounds { startsAtMs untilMs maxOccurrences }
@@ -3263,7 +3262,7 @@ var LIST_SCHEDULES = `
3263
3262
  query ToolkitListAgentSchedules($channelId: ID!, $after: String) {
3264
3263
  viewer { channel(id: $channelId) {
3265
3264
  schedules(input: { first: 64, after: $after }) {
3266
- edges { node { ${SCHEDULE_FIELDS} } }
3265
+ edges { node { channel { id } ${SCHEDULE_FIELDS} } }
3267
3266
  pageInfo { hasNextPage endCursor }
3268
3267
  }
3269
3268
  } }
@@ -3271,6 +3270,20 @@ query ToolkitListAgentSchedules($channelId: ID!, $after: String) {
3271
3270
  var UPDATE_SCHEDULE = `
3272
3271
  mutation ToolkitUpdateAgentSchedule($input: UpdateChannelScheduleInput!) {
3273
3272
  updateChannelSchedule(input: $input) {
3273
+ schedule { channel { id } ${SCHEDULE_FIELDS} }
3274
+ deleted
3275
+ }
3276
+ }`.trim();
3277
+ var LIST_SESSION_SCHEDULES = `
3278
+ query ToolkitListSessionSchedules($inboxPath: String!, $after: String) {
3279
+ viewer { sessionSchedules(inboxPath: $inboxPath, input: { first: 64, after: $after }) {
3280
+ edges { node { ${SCHEDULE_FIELDS} } }
3281
+ pageInfo { hasNextPage endCursor }
3282
+ } }
3283
+ }`.trim();
3284
+ var UPDATE_SESSION_SCHEDULE = `
3285
+ mutation ToolkitUpdateSessionSchedule($input: UpdateSessionScheduleInput!) {
3286
+ updateSessionSchedule(input: $input) {
3274
3287
  schedule { ${SCHEDULE_FIELDS} }
3275
3288
  deleted
3276
3289
  }
@@ -3281,6 +3294,7 @@ query ToolkitAgentChannel {
3281
3294
  }`.trim();
3282
3295
  var SCHEDULE_NAME = /^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/;
3283
3296
  var RFC3339 = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(Z|[+-](\d{2}):(\d{2}))$/i;
3297
+ var RFC3339_FRACTIONAL = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:\.\d{1,9})?(Z|[+-](\d{2}):(\d{2}))$/i;
3284
3298
  var ISO_DURATION = /^P(?:(\d+)D)?(?:T(?:(\d+)H)?(?:(\d+)M)?(?:(\d+)S)?)?$/;
3285
3299
  var GRAPHQL_STATUS_BY_CODE = {
3286
3300
  INVALID_ARGUMENT: 400,
@@ -3304,16 +3318,17 @@ var SchedulesResource = class {
3304
3318
  client;
3305
3319
  async list(params) {
3306
3320
  this.client._requireAuth();
3307
- const id = channelID(params.channelId);
3321
+ const target = targetInput(params);
3322
+ const inbox = "inboxPath" in target;
3308
3323
  const schedules = [];
3309
3324
  let after = null;
3310
3325
  const seenCursors = /* @__PURE__ */ new Set();
3311
3326
  for (; ; ) {
3312
3327
  const data = await this.graphql(
3313
- LIST_SCHEDULES,
3314
- { channelId: id, after }
3328
+ inbox ? LIST_SESSION_SCHEDULES : LIST_SCHEDULES,
3329
+ { ...target, after }
3315
3330
  );
3316
- const connection2 = data.viewer?.channel?.schedules;
3331
+ const connection2 = inbox ? data.viewer?.sessionSchedules : data.viewer?.channel?.schedules;
3317
3332
  if (!connection2?.edges) throw scheduleNotFound();
3318
3333
  for (const edge of connection2.edges) {
3319
3334
  if (!edge?.node) throw scheduleEmptyResponse();
@@ -3329,15 +3344,14 @@ var SchedulesResource = class {
3329
3344
  async put(params) {
3330
3345
  this.client._requireAuth();
3331
3346
  const input = {
3332
- channelId: channelID(params.channelId),
3347
+ ...targetInput(params),
3333
3348
  name: requireName(params.name),
3334
3349
  definition: {
3335
3350
  ...ruleInput(params.rule, params.bounds),
3336
3351
  message: { text: requireText(params.text) }
3337
3352
  }
3338
3353
  };
3339
- const data = await this.graphql(UPDATE_SCHEDULE, { input });
3340
- const schedule = data.updateChannelSchedule?.schedule;
3354
+ const schedule = (await this.update(input))?.schedule;
3341
3355
  if (!schedule) throw scheduleEmptyResponse();
3342
3356
  return fromWireSchedule(schedule);
3343
3357
  }
@@ -3349,11 +3363,11 @@ var SchedulesResource = class {
3349
3363
  }
3350
3364
  async delete(params) {
3351
3365
  this.client._requireAuth();
3352
- const data = await this.graphql(UPDATE_SCHEDULE, {
3353
- input: { ...managementInput(params), lifecycle: "REMOVED" }
3366
+ const result = await this.update({
3367
+ ...managementInput(params),
3368
+ lifecycle: "REMOVED"
3354
3369
  });
3355
- if (data.updateChannelSchedule?.deleted !== true)
3356
- throw scheduleEmptyResponse();
3370
+ if (result?.deleted !== true) throw scheduleEmptyResponse();
3357
3371
  }
3358
3372
  /** Resolve the authenticated viewer's unique Agent Channel for CLI defaults. */
3359
3373
  async agentChannelId() {
@@ -3367,13 +3381,15 @@ var SchedulesResource = class {
3367
3381
  }
3368
3382
  async manage(lifecycle, params) {
3369
3383
  this.client._requireAuth();
3370
- const data = await this.graphql(UPDATE_SCHEDULE, {
3371
- input: { ...managementInput(params), lifecycle }
3372
- });
3373
- const schedule = data.updateChannelSchedule?.schedule;
3384
+ const schedule = (await this.update({ ...managementInput(params), lifecycle }))?.schedule;
3374
3385
  if (!schedule) throw scheduleEmptyResponse();
3375
3386
  return fromWireSchedule(schedule);
3376
3387
  }
3388
+ async update(input) {
3389
+ const inbox = "inboxPath" in input;
3390
+ const data = await this.graphql(inbox ? UPDATE_SESSION_SCHEDULE : UPDATE_SCHEDULE, { input });
3391
+ return inbox ? data.updateSessionSchedule : data.updateChannelSchedule;
3392
+ }
3377
3393
  async graphql(query, variables) {
3378
3394
  const response = await this.client._request("POST", "/query", {
3379
3395
  body: variables === void 0 ? { query } : { query, variables }
@@ -3524,10 +3540,24 @@ function fromWireRule(rule) {
3524
3540
  }
3525
3541
  function managementInput(params) {
3526
3542
  return {
3527
- channelId: channelID(params.channelId),
3543
+ ...targetInput(params),
3528
3544
  name: requireName(params.name)
3529
3545
  };
3530
3546
  }
3547
+ function targetInput(target) {
3548
+ if (target.channelId !== void 0 === (target.inboxPath !== void 0))
3549
+ throw invalid("exactly one of channelId or inboxPath is required");
3550
+ if (target.channelId !== void 0)
3551
+ return { channelId: channelID(target.channelId) };
3552
+ const path = target.inboxPath;
3553
+ const size = typeof path === "string" ? utf8Size(path) : void 0;
3554
+ if (typeof path !== "string" || size === void 0 || size > 2048 || !path.startsWith("/") || path.includes("\0") || path.slice(1).split("/").some((segment) => segment === "" || segment === "." || segment === ".."))
3555
+ throw invalid("inboxPath must be a canonical absolute ALFS Inbox path");
3556
+ const transcript = path.endsWith(".inbox.jsonl") ? path.slice(0, -".inbox.jsonl".length) + ".jsonl" : path.endsWith(".inbox") && !path.endsWith(".jsonl.inbox") ? path.slice(0, -".inbox".length) : void 0;
3557
+ if (transcript === void 0 || /\.inbox(?:\.jsonl)?$/.test(transcript) || /\.lock(?:\.recovery|\.heartbeat-[^/]+|\.stale-[^/]+)?$/.test(transcript) || transcript.endsWith("/.jsonl"))
3558
+ throw invalid("inboxPath must identify a standard Session Inbox sidecar");
3559
+ return { inboxPath: path };
3560
+ }
3531
3561
  function channelID(value) {
3532
3562
  if (typeof value === "number" && (!Number.isSafeInteger(value) || value <= 0)) {
3533
3563
  throw invalid(
@@ -3572,8 +3602,8 @@ function durationMilliseconds(value, minimumSeconds) {
3572
3602
  if (!Number.isSafeInteger(result)) throw invalid("duration is out of range");
3573
3603
  return result;
3574
3604
  }
3575
- function timestampMilliseconds(value) {
3576
- const match = RFC3339.exec(value);
3605
+ function timestampMilliseconds(value, fractional = false) {
3606
+ const match = (fractional ? RFC3339_FRACTIONAL : RFC3339).exec(value);
3577
3607
  if (!match) throw invalid("timestamp must be RFC3339 with a timezone");
3578
3608
  const [year, month, day, hour, minute, second] = match.slice(1, 7).map(Number);
3579
3609
  const offsetHour = Number(match[8] ?? 0);
@@ -3616,6 +3646,243 @@ function scheduleEmptyResponse() {
3616
3646
  );
3617
3647
  }
3618
3648
 
3649
+ // src/resources/steward.ts
3650
+ var GRAPHQL_STATUS_BY_CODE2 = {
3651
+ INVALID_ARGUMENT: 400,
3652
+ UNAUTHENTICATED: 401,
3653
+ PERMISSION_DENIED: 403,
3654
+ NOT_FOUND: 404,
3655
+ ALREADY_EXISTS: 409,
3656
+ ABORTED: 409,
3657
+ FAILED_PRECONDITION: 412,
3658
+ RESOURCE_EXHAUSTED: 429,
3659
+ INTERNAL: 500,
3660
+ UNKNOWN: 500,
3661
+ DATA_LOSS: 500,
3662
+ UNAVAILABLE: 503,
3663
+ DEADLINE_EXCEEDED: 504
3664
+ };
3665
+ var DECIDE = `
3666
+ mutation ToolkitStewardDecide($input: UpdateStewardDeliveryInput!) {
3667
+ updateStewardDelivery(input: $input) { delivery { deliveryId state } }
3668
+ }`.trim();
3669
+ var FORWARD = `
3670
+ mutation ToolkitStewardForward($input: UpdateStewardDeliveryInput!) {
3671
+ updateStewardDelivery(input: $input) { delivery { deliveryId state channelMessageId } }
3672
+ }`.trim();
3673
+ var SEND = `
3674
+ mutation ToolkitStewardSend($input: PostStewardMessageInput!) {
3675
+ postStewardMessage(input: $input) { message { channelMessageId requestId } }
3676
+ }`.trim();
3677
+ var PENDING = `
3678
+ query ToolkitStewardPending($inboxPath: String!, $input: StewardDigestPendingInput) {
3679
+ viewer {
3680
+ stewardDigestPending(inboxPath: $inboxPath, input: $input) {
3681
+ edges {
3682
+ cursor
3683
+ node { deliveryId feedEntryId source { kind id } decisionReason consumedAtMs }
3684
+ }
3685
+ pageInfo { hasNextPage endCursor }
3686
+ windowSinceMs
3687
+ windowUntilMs
3688
+ }
3689
+ }
3690
+ }`.trim();
3691
+ var BRIEFED = `
3692
+ mutation ToolkitStewardBriefed($input: CompleteStewardBriefInput!) {
3693
+ completeStewardBrief(input: $input) { ok }
3694
+ }`.trim();
3695
+ var DECISIONS = /* @__PURE__ */ new Set([
3696
+ "immediate",
3697
+ "digest",
3698
+ "suppress"
3699
+ ]);
3700
+ var DELIVERY_ID = /^[1-9][0-9]{0,18}$/;
3701
+ function invalid2(message) {
3702
+ return new AlvaError("INVALID_ARGUMENT", message, 400);
3703
+ }
3704
+ function requireInboxPath(target) {
3705
+ if (!target || typeof target.inboxPath !== "string" || target.inboxPath === "")
3706
+ throw invalid2("steward commands require the steward Session Inbox path");
3707
+ return target.inboxPath;
3708
+ }
3709
+ function requireDeliveryId(value, label = "delivery id") {
3710
+ if (!DELIVERY_ID.test(value))
3711
+ throw invalid2(`${label} must be a positive integer`);
3712
+ return value;
3713
+ }
3714
+ function requireDeliveryIds(values) {
3715
+ if (values.length === 0)
3716
+ throw invalid2("at least one delivery id is required");
3717
+ const unique = /* @__PURE__ */ new Set();
3718
+ for (const value of values) {
3719
+ requireDeliveryId(value);
3720
+ if (unique.has(value)) throw invalid2(`duplicate delivery id ${value}`);
3721
+ unique.add(value);
3722
+ }
3723
+ return [...unique];
3724
+ }
3725
+ function requireDecision(value) {
3726
+ if (!DECISIONS.has(value))
3727
+ throw invalid2("decision must be one of immediate, digest, suppress");
3728
+ return value;
3729
+ }
3730
+ function generateRequestId() {
3731
+ const webcrypto = globalThis.crypto;
3732
+ if (typeof webcrypto?.randomUUID === "function")
3733
+ return webcrypto.randomUUID();
3734
+ const bytes = new Uint8Array(16);
3735
+ if (typeof webcrypto?.getRandomValues === "function") {
3736
+ webcrypto.getRandomValues(bytes);
3737
+ } else {
3738
+ for (let i = 0; i < bytes.length; i += 1)
3739
+ bytes[i] = Math.floor(Math.random() * 256);
3740
+ }
3741
+ bytes[6] = bytes[6] & 15 | 64;
3742
+ bytes[8] = bytes[8] & 63 | 128;
3743
+ const hex = Array.from(bytes, (b) => b.toString(16).padStart(2, "0")).join(
3744
+ ""
3745
+ );
3746
+ return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
3747
+ }
3748
+ function requireRequestId(value) {
3749
+ if (value === void 0) return generateRequestId();
3750
+ if (!/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(
3751
+ value
3752
+ ))
3753
+ throw invalid2("request id must be a UUID");
3754
+ return value;
3755
+ }
3756
+ function emptyResponse() {
3757
+ return new AlvaError("EMPTY_RESPONSE", "steward response was empty", 502);
3758
+ }
3759
+ var StewardResource = class {
3760
+ constructor(client) {
3761
+ this.client = client;
3762
+ }
3763
+ client;
3764
+ async decide(params) {
3765
+ this.client._requireAuth();
3766
+ const reason = params.reason?.trim();
3767
+ if (!reason) throw invalid2("a decision reason is required");
3768
+ const data = await this.graphql(DECIDE, {
3769
+ input: {
3770
+ inboxPath: requireInboxPath(params),
3771
+ deliveryId: requireDeliveryId(params.deliveryId),
3772
+ decision: {
3773
+ decision: requireDecision(params.decision).toUpperCase(),
3774
+ reason
3775
+ }
3776
+ }
3777
+ });
3778
+ const delivery = data.updateStewardDelivery?.delivery;
3779
+ if (!delivery) throw emptyResponse();
3780
+ return { state: delivery.state };
3781
+ }
3782
+ async forward(params) {
3783
+ this.client._requireAuth();
3784
+ const data = await this.graphql(FORWARD, {
3785
+ input: {
3786
+ inboxPath: requireInboxPath(params),
3787
+ deliveryId: requireDeliveryId(params.deliveryId),
3788
+ forward: { requestId: requireRequestId(params.requestId) }
3789
+ }
3790
+ });
3791
+ const delivery = data.updateStewardDelivery?.delivery;
3792
+ if (!delivery || !delivery.channelMessageId) throw emptyResponse();
3793
+ return {
3794
+ channelMessageId: delivery.channelMessageId,
3795
+ state: delivery.state
3796
+ };
3797
+ }
3798
+ async send(params) {
3799
+ this.client._requireAuth();
3800
+ if (typeof params.body !== "string" || params.body.trim() === "")
3801
+ throw invalid2("a message body is required");
3802
+ const data = await this.graphql(SEND, {
3803
+ input: {
3804
+ inboxPath: requireInboxPath(params),
3805
+ requestId: requireRequestId(params.requestId),
3806
+ body: params.body,
3807
+ deliveryIds: requireDeliveryIds(params.deliveryIds)
3808
+ }
3809
+ });
3810
+ const message = data.postStewardMessage?.message;
3811
+ if (!message) throw emptyResponse();
3812
+ return message;
3813
+ }
3814
+ async pending(params) {
3815
+ this.client._requireAuth();
3816
+ const first = params.first ?? 50;
3817
+ if (!Number.isInteger(first) || first < 1 || first > 100)
3818
+ throw invalid2("first must be an integer between 1 and 100");
3819
+ const input = { first };
3820
+ if (params.after !== void 0 && params.after !== "") {
3821
+ input.after = params.after;
3822
+ } else {
3823
+ for (const [label, value] of [
3824
+ ["sinceMs", params.sinceMs],
3825
+ ["untilMs", params.untilMs]
3826
+ ]) {
3827
+ if (value !== void 0 && (!Number.isSafeInteger(value) || value <= 0))
3828
+ throw invalid2(`${label} must be a positive safe integer timestamp`);
3829
+ }
3830
+ if (params.sinceMs !== void 0 && params.untilMs !== void 0 && params.untilMs <= params.sinceMs)
3831
+ throw invalid2("untilMs must be after sinceMs");
3832
+ if (params.sinceMs !== void 0) input.sinceMs = params.sinceMs;
3833
+ if (params.untilMs !== void 0) input.untilMs = params.untilMs;
3834
+ }
3835
+ const data = await this.graphql(PENDING, { inboxPath: requireInboxPath(params), input });
3836
+ const page = data.viewer?.stewardDigestPending;
3837
+ if (!page || !Array.isArray(page.edges)) throw emptyResponse();
3838
+ const windowSinceMs = page.windowSinceMs ?? 0;
3839
+ const windowUntilMs = page.windowUntilMs ?? 0;
3840
+ if (!Number.isSafeInteger(windowSinceMs) || !Number.isSafeInteger(windowUntilMs) || windowSinceMs <= 0 || windowUntilMs <= windowSinceMs)
3841
+ throw emptyResponse();
3842
+ const items = page.edges.map((edge) => edge.node);
3843
+ const nextCursor = page.pageInfo?.hasNextPage === true && page.pageInfo.endCursor ? page.pageInfo.endCursor : null;
3844
+ return {
3845
+ items,
3846
+ nextCursor,
3847
+ windowSinceMs,
3848
+ windowUntilMs
3849
+ };
3850
+ }
3851
+ async briefed(params) {
3852
+ this.client._requireAuth();
3853
+ const digestRunId = params.digestRunId?.trim();
3854
+ if (!digestRunId) throw invalid2("a digest run id is required");
3855
+ const data = await this.graphql(BRIEFED, {
3856
+ input: {
3857
+ inboxPath: requireInboxPath(params),
3858
+ deliveryIds: requireDeliveryIds(params.deliveryIds),
3859
+ digestRunId
3860
+ }
3861
+ });
3862
+ if (data.completeStewardBrief?.ok !== true) throw emptyResponse();
3863
+ return { ok: true };
3864
+ }
3865
+ async graphql(query, variables) {
3866
+ const response = await this.client._request("POST", "/query", {
3867
+ body: { query, variables }
3868
+ });
3869
+ if (!response || typeof response !== "object") throw emptyResponse();
3870
+ if (response.errors?.length) {
3871
+ const codes = response.errors.map((error) => error.extensions?.code);
3872
+ const canonicalCode = new Set(codes).size === 1 && typeof codes[0] === "string" ? codes[0] : void 0;
3873
+ const canonicalStatus = canonicalCode ? GRAPHQL_STATUS_BY_CODE2[canonicalCode] : void 0;
3874
+ throw new AlvaError(
3875
+ canonicalCode !== void 0 && canonicalStatus !== void 0 ? canonicalCode : "GRAPHQL_ERROR",
3876
+ response.errors.map((error) => error.message).filter((message) => typeof message === "string").join("; ") || "GraphQL request failed",
3877
+ canonicalStatus ?? 502,
3878
+ { errors: response.errors }
3879
+ );
3880
+ }
3881
+ if (!response.data) throw emptyResponse();
3882
+ return response.data;
3883
+ }
3884
+ };
3885
+
3619
3886
  // src/resources/tradingPairs.ts
3620
3887
  function isRecord(value) {
3621
3888
  return typeof value === "object" && value !== null && !Array.isArray(value);
@@ -3801,14 +4068,320 @@ var TradingPairsResource = class {
3801
4068
  }
3802
4069
  };
3803
4070
 
4071
+ // src/resources/theses.ts
4072
+ var MAX_SIGNED_INT64 = 9223372036854775807n;
4073
+ var UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
4074
+ var UNPAIRED_SURROGATE = /[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]/;
4075
+ var encoder = new TextEncoder();
4076
+ var ThesesResource = class {
4077
+ constructor(client) {
4078
+ this.client = client;
4079
+ }
4080
+ client;
4081
+ async create(params) {
4082
+ this.client._requireAuth();
4083
+ const body = createBody(params);
4084
+ return thesisResponse(
4085
+ await this.client._request("POST", "/api/v1/theses", { body })
4086
+ );
4087
+ }
4088
+ async get(id) {
4089
+ this.client._requireAuth();
4090
+ return thesisGetResponse(
4091
+ await this.client._request("GET", `/api/v1/theses/${requireID(id, "id")}`)
4092
+ );
4093
+ }
4094
+ async update(id, params) {
4095
+ this.client._requireAuth();
4096
+ const body = updateBody(params);
4097
+ return thesisResponse(
4098
+ await this.client._request(
4099
+ "PUT",
4100
+ `/api/v1/theses/${requireID(id, "id")}`,
4101
+ {
4102
+ body
4103
+ }
4104
+ )
4105
+ );
4106
+ }
4107
+ async close(id, params) {
4108
+ this.client._requireAuth();
4109
+ const body = {
4110
+ expected_author_version_id: requireID(
4111
+ params.expected_author_version_id,
4112
+ "expected_author_version_id"
4113
+ )
4114
+ };
4115
+ if (params.note !== void 0) body.note = requireText2(params.note, "note");
4116
+ return thesisResponse(
4117
+ await this.client._request(
4118
+ "POST",
4119
+ `/api/v1/theses/${requireID(id, "id")}/close`,
4120
+ { body }
4121
+ )
4122
+ );
4123
+ }
4124
+ async delete(id) {
4125
+ this.client._requireAuth();
4126
+ const response = await this.client._request(
4127
+ "DELETE",
4128
+ `/api/v1/theses/${requireID(id, "id")}`
4129
+ );
4130
+ if (response === void 0) return {};
4131
+ if (!isRecord2(response) || Object.keys(response).length !== 0) {
4132
+ throw invalidResponse2("delete response must be {}");
4133
+ }
4134
+ return {};
4135
+ }
4136
+ async rewrite(params) {
4137
+ this.client._requireAuth();
4138
+ const body = requireBody(params.body);
4139
+ const mode = params.mode === void 0 ? "reformat" : requireRewriteMode(params.mode);
4140
+ const response = await this.client._request(
4141
+ "POST",
4142
+ "/api/v1/theses/rewrite",
4143
+ {
4144
+ body: { body, mode }
4145
+ }
4146
+ );
4147
+ if (!isRecord2(response) || typeof response.body !== "string") {
4148
+ throw invalidResponse2("rewrite response must contain a string body");
4149
+ }
4150
+ return { body: responseBody(response.body) };
4151
+ }
4152
+ };
4153
+ function createBody(params) {
4154
+ return {
4155
+ request_id: requireRequestID(params.request_id),
4156
+ body: requireBody(params.body),
4157
+ title: requireTitle(params.title ?? ""),
4158
+ entity_ids: requireIDs(params.entity_ids ?? [], "entity_ids"),
4159
+ visibility: requireVisibility(params.visibility ?? "public")
4160
+ };
4161
+ }
4162
+ function updateBody(params) {
4163
+ return {
4164
+ request_id: requireRequestID(params.request_id),
4165
+ expected_author_version_id: requireID(
4166
+ params.expected_author_version_id,
4167
+ "expected_author_version_id"
4168
+ ),
4169
+ body: requireBody(params.body),
4170
+ title: requireTitle(params.title ?? ""),
4171
+ entity_ids: requireIDs(params.entity_ids ?? [], "entity_ids"),
4172
+ visibility: requireVisibility(params.visibility),
4173
+ editorial: params.editorial ?? false
4174
+ };
4175
+ }
4176
+ function thesisResponse(response) {
4177
+ if (!isRecord2(response) || !isRecord2(response.thesis)) {
4178
+ throw invalidResponse2("response must contain thesis");
4179
+ }
4180
+ const thesis = response.thesis;
4181
+ const value = {
4182
+ id: responseID(thesis.id, "thesis.id"),
4183
+ author_version_id: responseID(
4184
+ thesis.author_version_id,
4185
+ "thesis.author_version_id"
4186
+ ),
4187
+ material_version_id: responseID(
4188
+ thesis.material_version_id,
4189
+ "thesis.material_version_id"
4190
+ ),
4191
+ title: responseTitle(thesis.title),
4192
+ body: responseBody(thesis.body),
4193
+ entity_ids: responseIDs(thesis.entity_ids, "thesis.entity_ids"),
4194
+ visibility: responseVisibility(thesis.visibility),
4195
+ closed: responseBoolean(thesis.closed, "thesis.closed"),
4196
+ closing_note: responseClosingNote(thesis.closing_note),
4197
+ author_kind: responseText(thesis.author_kind, "thesis.author_kind"),
4198
+ author_ref: responseText(thesis.author_ref, "thesis.author_ref")
4199
+ };
4200
+ return { thesis: value };
4201
+ }
4202
+ function thesisGetResponse(response) {
4203
+ const base = thesisResponse(response);
4204
+ if (!isRecord2(response) || !isRecord2(response.author)) {
4205
+ throw invalidResponse2("response must contain author");
4206
+ }
4207
+ const authorRecord = response.author;
4208
+ const author = {
4209
+ id: responseID(authorRecord.id, "author.id"),
4210
+ kind: responseText(authorRecord.kind, "author.kind"),
4211
+ display_name: responseText(
4212
+ authorRecord.display_name,
4213
+ "author.display_name"
4214
+ ),
4215
+ avatar_url: responseText(authorRecord.avatar_url, "author.avatar_url"),
4216
+ username: responseText(authorRecord.username, "author.username")
4217
+ };
4218
+ if (!Array.isArray(response.entities)) {
4219
+ throw invalidResponse2("response must contain entities");
4220
+ }
4221
+ if (response.entities.length !== base.thesis.entity_ids.length) {
4222
+ throw invalidResponse2("entities must match thesis.entity_ids");
4223
+ }
4224
+ const entities = response.entities.map((item, index) => {
4225
+ if (!isRecord2(item))
4226
+ throw invalidResponse2(`entities[${index}] must be an object`);
4227
+ const entity = {
4228
+ id: responseID(item.id, `entities[${index}].id`),
4229
+ ticker: responseText(item.ticker, `entities[${index}].ticker`),
4230
+ name: responseText(item.name, `entities[${index}].name`),
4231
+ icon_url: responseText(item.icon_url, `entities[${index}].icon_url`),
4232
+ kind: responseText(item.kind, `entities[${index}].kind`)
4233
+ };
4234
+ if (entity.id !== base.thesis.entity_ids[index]) {
4235
+ throw invalidResponse2("entities must preserve thesis.entity_ids order");
4236
+ }
4237
+ return entity;
4238
+ });
4239
+ return { thesis: base.thesis, author, entities };
4240
+ }
4241
+ function requireRequestID(value) {
4242
+ if (!UUID.test(value) || /^0{8}-0{4}-0{4}-0{4}-0{12}$/i.test(value)) {
4243
+ throw invalidArgument("request_id must be a non-zero RFC 4122 UUID");
4244
+ }
4245
+ return value;
4246
+ }
4247
+ function requireID(value, field) {
4248
+ if (typeof value !== "string" || !/^[1-9]\d*$/.test(value)) {
4249
+ throw invalidArgument(`${field} must be a positive int64 decimal string`);
4250
+ }
4251
+ const parsed = BigInt(value);
4252
+ if (parsed > MAX_SIGNED_INT64) {
4253
+ throw invalidArgument(`${field} must be a positive int64 decimal string`);
4254
+ }
4255
+ return value;
4256
+ }
4257
+ function requireIDs(value, field) {
4258
+ if (!Array.isArray(value)) throw invalidArgument(`${field} must be an array`);
4259
+ if (value.length > 20) {
4260
+ throw invalidArgument(`${field} must contain at most 20 IDs`);
4261
+ }
4262
+ return value.map((item, index) => requireID(item, `${field}[${index}]`));
4263
+ }
4264
+ function requireBody(value) {
4265
+ const body = requireText2(value, "body");
4266
+ if (body.trim().length === 0) throw invalidArgument("body must not be blank");
4267
+ if (encoder.encode(body).byteLength > 65536) {
4268
+ throw invalidArgument("body must be at most 65536 UTF-8 bytes");
4269
+ }
4270
+ return body;
4271
+ }
4272
+ function requireTitle(value) {
4273
+ const title = requireText2(value, "title");
4274
+ if (encoder.encode(title).byteLength > 500) {
4275
+ throw invalidArgument("title must be at most 500 UTF-8 bytes");
4276
+ }
4277
+ return title;
4278
+ }
4279
+ function requireVisibility(value) {
4280
+ const visibility = requireText2(value, "visibility");
4281
+ if (visibility !== "public" && visibility !== "private") {
4282
+ throw invalidArgument("visibility must be public or private");
4283
+ }
4284
+ return visibility;
4285
+ }
4286
+ function requireRewriteMode(value) {
4287
+ const mode = requireText2(value, "mode");
4288
+ if (mode === "reformat" || mode === "shorten" || mode === "enrich") {
4289
+ return mode;
4290
+ }
4291
+ throw invalidArgument("mode must be reformat, shorten, or enrich");
4292
+ }
4293
+ function requireText2(value, field) {
4294
+ if (typeof value !== "string")
4295
+ throw invalidArgument(`${field} must be a string`);
4296
+ if (UNPAIRED_SURROGATE.test(value)) {
4297
+ throw invalidArgument(`${field} contains invalid Unicode`);
4298
+ }
4299
+ if ((field === "body" || field === "title" || field === "note") && value.includes("\0")) {
4300
+ throw invalidArgument(`${field} must not contain NUL`);
4301
+ }
4302
+ return value;
4303
+ }
4304
+ function responseID(value, field) {
4305
+ if (typeof value === "number") {
4306
+ throw invalidResponse2(
4307
+ `${field} must be a decimal string; numeric IDs are unsafe`
4308
+ );
4309
+ }
4310
+ try {
4311
+ return requireID(value, field);
4312
+ } catch {
4313
+ throw invalidResponse2(`${field} must be a positive int64 decimal string`);
4314
+ }
4315
+ }
4316
+ function responseIDs(value, field) {
4317
+ if (!Array.isArray(value)) throw invalidResponse2(`${field} must be an array`);
4318
+ if (value.length > 20) {
4319
+ throw invalidResponse2(`${field} must contain at most 20 IDs`);
4320
+ }
4321
+ return value.map((item, index) => responseID(item, `${field}[${index}]`));
4322
+ }
4323
+ function responseText(value, field) {
4324
+ try {
4325
+ return requireText2(value, field);
4326
+ } catch {
4327
+ throw invalidResponse2(`${field} must be valid text`);
4328
+ }
4329
+ }
4330
+ function responseClosingNote(value) {
4331
+ try {
4332
+ return requireText2(value, "note");
4333
+ } catch {
4334
+ throw invalidResponse2("thesis.closing_note must be valid text");
4335
+ }
4336
+ }
4337
+ function responseBoolean(value, field) {
4338
+ if (typeof value !== "boolean")
4339
+ throw invalidResponse2(`${field} must be boolean`);
4340
+ return value;
4341
+ }
4342
+ function responseVisibility(value) {
4343
+ try {
4344
+ return requireVisibility(value);
4345
+ } catch {
4346
+ throw invalidResponse2("thesis.visibility must be public or private");
4347
+ }
4348
+ }
4349
+ function responseBody(value) {
4350
+ try {
4351
+ return requireBody(value);
4352
+ } catch {
4353
+ throw invalidResponse2(
4354
+ "response body must be nonblank valid text at most 65536 UTF-8 bytes"
4355
+ );
4356
+ }
4357
+ }
4358
+ function responseTitle(value) {
4359
+ try {
4360
+ return requireTitle(value);
4361
+ } catch {
4362
+ throw invalidResponse2(
4363
+ "response title must be valid text at most 500 UTF-8 bytes"
4364
+ );
4365
+ }
4366
+ }
4367
+ function isRecord2(value) {
4368
+ return typeof value === "object" && value !== null && !Array.isArray(value);
4369
+ }
4370
+ function invalidArgument(message) {
4371
+ return new AlvaError("INVALID_ARGUMENT", message, 400);
4372
+ }
4373
+ function invalidResponse2(message) {
4374
+ return new AlvaError("INVALID_RESPONSE", message, 502);
4375
+ }
4376
+
3804
4377
  // src/client.ts
3805
4378
  var DEFAULT_BASE_URL = "https://api-llm.prd.alva.ai";
3806
4379
  var DEFAULT_ARRAYS_BASE_URL = "https://data-tools.prd.space.id";
3807
- function isRecord2(value) {
4380
+ function isRecord3(value) {
3808
4381
  return typeof value === "object" && value !== null;
3809
4382
  }
3810
4383
  function stringField(value, field) {
3811
- if (!isRecord2(value)) return void 0;
4384
+ if (!isRecord3(value)) return void 0;
3812
4385
  const fieldValue = value[field];
3813
4386
  return typeof fieldValue === "string" && fieldValue ? fieldValue : void 0;
3814
4387
  }
@@ -3822,7 +4395,7 @@ function describeCause(cause) {
3822
4395
  if (cause.message) details.message = cause.message;
3823
4396
  const code = stringField(cause, "code");
3824
4397
  if (code) details.code = code;
3825
- } else if (isRecord2(cause)) {
4398
+ } else if (isRecord3(cause)) {
3826
4399
  const code = stringField(cause, "code");
3827
4400
  const name = stringField(cause, "name");
3828
4401
  const message = stringField(cause, "message");
@@ -3850,7 +4423,7 @@ function describeFetchFailure(err) {
3850
4423
  details.message = String(err);
3851
4424
  }
3852
4425
  const { message: causeMessage, details: causeDetails } = describeCause(
3853
- isRecord2(err) ? err.cause : void 0
4426
+ isRecord3(err) ? err.cause : void 0
3854
4427
  );
3855
4428
  if (causeDetails) {
3856
4429
  details.cause = causeDetails;
@@ -3881,6 +4454,8 @@ var AlvaClient = class {
3881
4454
  originSessionId;
3882
4455
  /** Session profile kind associated with originSessionId. */
3883
4456
  originSessionKind;
4457
+ /** Host-attached file Session target, distinct from the chat origin header. */
4458
+ originInboxPath;
3884
4459
  _fs;
3885
4460
  _run;
3886
4461
  _deploy;
@@ -3911,7 +4486,9 @@ var AlvaClient = class {
3911
4486
  _credits;
3912
4487
  _markets;
3913
4488
  _schedules;
4489
+ _steward;
3914
4490
  _tradingPairs;
4491
+ _theses;
3915
4492
  constructor(config) {
3916
4493
  this.baseUrl = config.baseUrl ?? DEFAULT_BASE_URL;
3917
4494
  this.arraysBaseUrl = config.arraysBaseUrl ?? DEFAULT_ARRAYS_BASE_URL;
@@ -3924,6 +4501,7 @@ var AlvaClient = class {
3924
4501
  this.signal = config.signal;
3925
4502
  this.originSessionId = config.originSessionId;
3926
4503
  this.originSessionKind = config.originSessionKind;
4504
+ this.originInboxPath = config.originInboxPath;
3927
4505
  }
3928
4506
  get fs() {
3929
4507
  return this._fs ??= new FsResource(this);
@@ -4015,6 +4593,12 @@ var AlvaClient = class {
4015
4593
  get schedules() {
4016
4594
  return this._schedules ??= new SchedulesResource(this);
4017
4595
  }
4596
+ get steward() {
4597
+ return this._steward ??= new StewardResource(this);
4598
+ }
4599
+ get theses() {
4600
+ return this._theses ??= new ThesesResource(this);
4601
+ }
4018
4602
  _requireAuth() {
4019
4603
  if (!this.pbsvToken && !this.viewer_token && !this.apiKey) {
4020
4604
  throw new AlvaError(
@@ -4631,7 +5215,7 @@ var installPlaybookRuntime = (targetWindow) => {
4631
5215
  };
4632
5216
 
4633
5217
  // src/index.ts
4634
- var VERSION = true ? "0.28.0" : "dev";
5218
+ var VERSION = true ? "0.28.1-beta.0" : "dev";
4635
5219
  export {
4636
5220
  AlertsResource,
4637
5221
  AlvaClient,
@@ -4646,6 +5230,8 @@ export {
4646
5230
  SUBSCRIBE_PROPOSE_MESSAGE,
4647
5231
  SUBSCRIBE_RESULT_MESSAGE,
4648
5232
  SchedulesResource,
5233
+ StewardResource,
5234
+ ThesesResource,
4649
5235
  TradingPairsResource,
4650
5236
  UDF_AUTH_REQUIRED_MESSAGE,
4651
5237
  UDF_CONSENT_REQUEST_MESSAGE,