@pulsarinteractive/geniustasker 0.1.0-beta.17 → 0.1.0-beta.19

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.
@@ -0,0 +1,67 @@
1
+ import * as z from 'zod/v4';
2
+ import catalog from '../remote/tool-catalog.json' with { type: 'json' };
3
+ import { fail } from './errors.mjs';
4
+
5
+ export const ticketStorageTools = new Map(
6
+ catalog
7
+ .filter(
8
+ (tool) =>
9
+ /^tasker_(storage|attachment)_/.test(tool.name) && tool.route?.startsWith('storage/'),
10
+ )
11
+ .map((tool) => [
12
+ tool.name.slice('tasker_'.length).replace('_', ' '),
13
+ { tool, schema: z.fromJSONSchema(tool.inputSchema) },
14
+ ]),
15
+ );
16
+
17
+ export async function ticketStorageRequest(client, command, input) {
18
+ const entry = ticketStorageTools.get(command);
19
+ const parsed = entry?.schema.safeParse(input);
20
+ if (!parsed?.success) {
21
+ fail(
22
+ 'invalid_arguments',
23
+ 'Supply one project and the exact fields for this storage operation.',
24
+ );
25
+ }
26
+ const { tool } = entry,
27
+ data = parsed.data;
28
+ if (!/^project:[A-Za-z0-9_-]{1,128}$/.test(data.scope)) {
29
+ fail('invalid_arguments', 'A selected project scope is required.');
30
+ }
31
+ if (
32
+ command === 'storage selection' &&
33
+ ((data.taskIds === undefined) === (data.attachmentIds === undefined) ||
34
+ (data.taskIds ?? data.attachmentIds).length !== 1)
35
+ ) {
36
+ fail('invalid_arguments', 'Estimate exactly one task or attachment.');
37
+ }
38
+ if (
39
+ tool.write &&
40
+ (data.action === 'remove' ? data.assetId !== undefined : data.assetId === undefined)
41
+ ) {
42
+ fail(
43
+ 'invalid_arguments',
44
+ 'Add or replace needs a published asset. Removal needs the existing attachment ID only.',
45
+ );
46
+ }
47
+ const result =
48
+ tool.method === 'POST'
49
+ ? await client.transport.request('/api/agents/v1/' + tool.route, {
50
+ method: 'POST',
51
+ json: data,
52
+ token: await client.accessToken(),
53
+ })
54
+ : await client.get(tool.route, data);
55
+ if (
56
+ tool.write &&
57
+ (result?.operationId !== data.operationId ||
58
+ result.attachmentId !== data.attachmentId ||
59
+ typeof result.revision !== 'string' ||
60
+ !Number.isSafeInteger(result.releasedBytes) ||
61
+ result.releasedBytes < 0 ||
62
+ typeof result.pendingRelease !== 'boolean')
63
+ ) {
64
+ fail('invalid_response', 'The server receipt did not match the selected attachment operation.');
65
+ }
66
+ return result;
67
+ }
package/src/transport.mjs CHANGED
@@ -56,7 +56,10 @@ export class Transport {
56
56
  this.timeoutMs = timeoutMs;
57
57
  this.signal = signal;
58
58
  }
59
- async request(path, { method = 'GET', form, json, token, query, bytes, binary = false } = {}) {
59
+ async request(
60
+ path,
61
+ { method = 'GET', form, json, token, query, bytes, partSha256, binary = false } = {},
62
+ ) {
60
63
  if (
61
64
  !(path.startsWith('/api/agents/') || path === '/.well-known/oauth-authorization-server') ||
62
65
  path.startsWith('//')
@@ -80,17 +83,31 @@ export class Transport {
80
83
  }
81
84
  }
82
85
  }
86
+ const ticketPart =
87
+ /^\/api\/agents\/v1\/attachment-uploads\/parts\/(?:[1-9]|1[0-9]|2[0-4])$/.test(url.pathname);
88
+ const ticketUpload = ticketPart || url.pathname === '/api/agents/v1/attachment-uploads/content';
89
+ if (
90
+ (partSha256 !== undefined && !ticketPart) ||
91
+ (ticketPart && (typeof partSha256 !== 'string' || !/^[a-f0-9]{64}$/.test(partSha256))) ||
92
+ (ticketUpload && (bytes === undefined || binary || method !== 'PUT'))
93
+ ) {
94
+ fail(
95
+ 'invalid_arguments',
96
+ 'Ticket upload bytes require their bound route and a verified part digest.',
97
+ );
98
+ }
83
99
  const feedbackMedia =
84
100
  /^\/api\/agents\/v1\/feedback\/media\/[a-f0-9]{8}-(?:[a-f0-9]{4}-){3}[a-f0-9]{12}\/content$/.test(
85
101
  url.pathname,
86
102
  );
87
103
  if (
88
104
  (bytes !== undefined || binary) &&
89
- ((!feedbackMedia && url.pathname !== '/api/agents/v1/media/content') ||
105
+ ((!ticketUpload && !feedbackMedia && url.pathname !== '/api/agents/v1/media/content') ||
90
106
  (feedbackMedia &&
91
107
  (url.search || (bytes !== undefined ? method !== 'PUT' : method !== 'GET'))) ||
92
108
  (bytes !== undefined &&
93
- (!Buffer.isBuffer(bytes) || bytes.length > (feedbackMedia ? 4_000_000 : 15_000_000))) ||
109
+ (!Buffer.isBuffer(bytes) ||
110
+ bytes.length > (ticketPart ? 8_388_608 : feedbackMedia ? 4_000_000 : 15_000_000))) ||
94
111
  (bytes !== undefined && (json !== undefined || form)))
95
112
  ) {
96
113
  fail('invalid_arguments', 'Binary transfer requires the bounded delegated media endpoint.');
@@ -114,6 +131,7 @@ export class Transport {
114
131
  redirect: 'error',
115
132
  signal,
116
133
  headers: {
134
+ ...(partSha256 ? { 'x-part-sha256': partSha256 } : {}),
117
135
  Accept: binary ? 'application/octet-stream' : 'application/json',
118
136
  ...(token ? { Authorization: `Bearer ${token}` } : {}),
119
137
  ...(bytes !== undefined