teamshare-bridge 0.25.11 → 0.25.12
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/lib/documents/bytes.d.ts +25 -0
- package/dist/lib/documents/bytes.js +40 -0
- package/dist/lib/documents/bytes.js.map +1 -0
- package/dist/lib/tools/process-image.d.ts +2 -2
- package/dist/lib/tools/process-image.js +31 -12
- package/dist/lib/tools/process-image.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Download a TeamShare document's bytes with a RUN's identity (2026-10).
|
|
3
|
+
*
|
|
4
|
+
* A document id is the stable reference; the storage URL behind it is private
|
|
5
|
+
* and answers 403 to anyone outside the server. Node tools that receive a
|
|
6
|
+
* document id (a builder upload stores the id in its file param, a render
|
|
7
|
+
* chain passes `documentId`) resolve it through `GET /documents/:id/download`
|
|
8
|
+
* authenticated with the run's own agent key — resolved by id from the
|
|
9
|
+
* command's addressed agent, exactly like a task session.
|
|
10
|
+
*
|
|
11
|
+
* Used by: process-image (uploaded image), and any future node tool that needs
|
|
12
|
+
* an input document's bytes.
|
|
13
|
+
*/
|
|
14
|
+
import { type SourceApi } from './source';
|
|
15
|
+
import type { ToolRunContext } from '../tools/runner';
|
|
16
|
+
/** A TeamShare document id (the uuid shape the API mints). */
|
|
17
|
+
export declare const DOCUMENT_ID_RE: RegExp;
|
|
18
|
+
/** The API client for a run's context, or null when the context has no key. */
|
|
19
|
+
export declare function apiFromRunContext(ctx?: ToolRunContext): SourceApi | null;
|
|
20
|
+
/**
|
|
21
|
+
* Bytes of one document, authenticated as the run's agent. Throws with the
|
|
22
|
+
* API's own error code (HTTP status + code) when the document cannot be read —
|
|
23
|
+
* callers surface it instead of guessing why the bytes never arrived.
|
|
24
|
+
*/
|
|
25
|
+
export declare function fetchRunDocumentBytes(ctx: ToolRunContext | undefined, documentId: string): Promise<Buffer>;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DOCUMENT_ID_RE = void 0;
|
|
4
|
+
exports.apiFromRunContext = apiFromRunContext;
|
|
5
|
+
exports.fetchRunDocumentBytes = fetchRunDocumentBytes;
|
|
6
|
+
/**
|
|
7
|
+
* Download a TeamShare document's bytes with a RUN's identity (2026-10).
|
|
8
|
+
*
|
|
9
|
+
* A document id is the stable reference; the storage URL behind it is private
|
|
10
|
+
* and answers 403 to anyone outside the server. Node tools that receive a
|
|
11
|
+
* document id (a builder upload stores the id in its file param, a render
|
|
12
|
+
* chain passes `documentId`) resolve it through `GET /documents/:id/download`
|
|
13
|
+
* authenticated with the run's own agent key — resolved by id from the
|
|
14
|
+
* command's addressed agent, exactly like a task session.
|
|
15
|
+
*
|
|
16
|
+
* Used by: process-image (uploaded image), and any future node tool that needs
|
|
17
|
+
* an input document's bytes.
|
|
18
|
+
*/
|
|
19
|
+
const source_1 = require("./source");
|
|
20
|
+
/** A TeamShare document id (the uuid shape the API mints). */
|
|
21
|
+
exports.DOCUMENT_ID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
22
|
+
/** The API client for a run's context, or null when the context has no key. */
|
|
23
|
+
function apiFromRunContext(ctx) {
|
|
24
|
+
if (!ctx?.baseUrl || !ctx.apiKey)
|
|
25
|
+
return null;
|
|
26
|
+
return { baseUrl: ctx.baseUrl, apiKey: ctx.apiKey };
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Bytes of one document, authenticated as the run's agent. Throws with the
|
|
30
|
+
* API's own error code (HTTP status + code) when the document cannot be read —
|
|
31
|
+
* callers surface it instead of guessing why the bytes never arrived.
|
|
32
|
+
*/
|
|
33
|
+
async function fetchRunDocumentBytes(ctx, documentId) {
|
|
34
|
+
const api = apiFromRunContext(ctx);
|
|
35
|
+
if (!api) {
|
|
36
|
+
throw new Error('No API credentials on this machine to download the document — a bridge action runs with the run agent\u2019s key, and none could be resolved here.');
|
|
37
|
+
}
|
|
38
|
+
return (0, source_1.fetchDocumentSource)(api, { documentId });
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=bytes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bytes.js","sourceRoot":"","sources":["../../../src/lib/documents/bytes.ts"],"names":[],"mappings":";;;AAqBA,8CAGC;AAOD,sDAWC;AA1CD;;;;;;;;;;;;GAYG;AACH,qCAA+D;AAG/D,8DAA8D;AACjD,QAAA,cAAc,GACzB,iEAAiE,CAAC;AAEpE,+EAA+E;AAC/E,SAAgB,iBAAiB,CAAC,GAAoB;IACpD,IAAI,CAAC,GAAG,EAAE,OAAO,IAAI,CAAC,GAAG,CAAC,MAAM;QAAE,OAAO,IAAI,CAAC;IAC9C,OAAO,EAAE,OAAO,EAAE,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,CAAC;AACtD,CAAC;AAED;;;;GAIG;AACI,KAAK,UAAU,qBAAqB,CACzC,GAA+B,EAC/B,UAAkB;IAElB,MAAM,GAAG,GAAG,iBAAiB,CAAC,GAAG,CAAC,CAAC;IACnC,IAAI,CAAC,GAAG,EAAE,CAAC;QACT,MAAM,IAAI,KAAK,CACb,oJAAoJ,CACrJ,CAAC;IACJ,CAAC;IACD,OAAO,IAAA,4BAAmB,EAAC,GAAG,EAAE,EAAE,UAAU,EAAE,CAAC,CAAC;AAClD,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { ToolModule, ToolResult } from './runner';
|
|
1
|
+
import type { ToolModule, ToolResult, ToolRunContext } from './runner';
|
|
2
2
|
export declare class ProcessImageTool implements ToolModule {
|
|
3
3
|
key: string;
|
|
4
|
-
run(params: Record<string, unknown
|
|
4
|
+
run(params: Record<string, unknown>, ctx?: ToolRunContext): Promise<ToolResult>;
|
|
5
5
|
}
|
|
@@ -9,22 +9,41 @@ exports.ProcessImageTool = void 0;
|
|
|
9
9
|
* Uses sharp for resize, crop, thumbnail, and format conversion.
|
|
10
10
|
*/
|
|
11
11
|
const sharp_1 = __importDefault(require("sharp"));
|
|
12
|
+
const bytes_1 = require("../documents/bytes");
|
|
12
13
|
class ProcessImageTool {
|
|
13
14
|
key = 'process-image';
|
|
14
|
-
async run(params) {
|
|
15
|
+
async run(params, ctx) {
|
|
15
16
|
const operation = String(params.operation ?? 'resize');
|
|
16
|
-
|
|
17
|
-
//
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
17
|
+
// A Buffer arrives materialized; everything else is a reference and must
|
|
18
|
+
// be RESOLVED. (The old guard tested `!inputBuffer` against the very value
|
|
19
|
+
// it was about to inspect, so a string reference could never take it.)
|
|
20
|
+
let inputBuffer = params.inputBuffer instanceof Buffer ? params.inputBuffer : undefined;
|
|
21
|
+
if (!inputBuffer && typeof params.inputBuffer === 'string') {
|
|
22
|
+
const value = params.inputBuffer.trim();
|
|
23
|
+
if (bytes_1.DOCUMENT_ID_RE.test(value)) {
|
|
24
|
+
// The builder stores the uploaded image's DOCUMENT ID (2026-10) —
|
|
25
|
+
// resolve it with the run's identity. A storage URL would answer 403
|
|
26
|
+
// here (private delivery), which used to look like a broken upload.
|
|
27
|
+
try {
|
|
28
|
+
inputBuffer = await (0, bytes_1.fetchRunDocumentBytes)(ctx, value);
|
|
29
|
+
}
|
|
30
|
+
catch (err) {
|
|
31
|
+
return {
|
|
32
|
+
outputs: [],
|
|
33
|
+
error: `Could not load the image document: ${err instanceof Error ? err.message : String(err)}`,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
25
36
|
}
|
|
26
|
-
|
|
27
|
-
|
|
37
|
+
else if (/^https?:\/\//i.test(value)) {
|
|
38
|
+
// Legacy/external URL: direct fetch (public storage only).
|
|
39
|
+
try {
|
|
40
|
+
const res = await fetch(value);
|
|
41
|
+
if (res.ok)
|
|
42
|
+
inputBuffer = Buffer.from(await res.arrayBuffer());
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
/* fall through to the missing-buffer error */
|
|
46
|
+
}
|
|
28
47
|
}
|
|
29
48
|
}
|
|
30
49
|
const width = params.width ? Number(params.width) : undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"process-image.js","sourceRoot":"","sources":["../../../src/lib/tools/process-image.ts"],"names":[],"mappings":";;;;;;AAAA;;;GAGG;AACH,kDAA0B;
|
|
1
|
+
{"version":3,"file":"process-image.js","sourceRoot":"","sources":["../../../src/lib/tools/process-image.ts"],"names":[],"mappings":";;;;;;AAAA;;;GAGG;AACH,kDAA0B;AAE1B,8CAG4B;AAE5B,MAAa,gBAAgB;IAC3B,GAAG,GAAG,eAAe,CAAC;IAEtB,KAAK,CAAC,GAAG,CACP,MAA+B,EAC/B,GAAoB;QAEpB,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC,SAAS,IAAI,QAAQ,CAAC,CAAC;QACvD,yEAAyE;QACzE,2EAA2E;QAC3E,uEAAuE;QACvE,IAAI,WAAW,GACb,MAAM,CAAC,WAAW,YAAY,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC,SAAS,CAAC;QACxE,IAAI,CAAC,WAAW,IAAI,OAAO,MAAM,CAAC,WAAW,KAAK,QAAQ,EAAE,CAAC;YAC3D,MAAM,KAAK,GAAG,MAAM,CAAC,WAAW,CAAC,IAAI,EAAE,CAAC;YACxC,IAAI,sBAAc,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;gBAC/B,kEAAkE;gBAClE,qEAAqE;gBACrE,oEAAoE;gBACpE,IAAI,CAAC;oBACH,WAAW,GAAG,MAAM,IAAA,6BAAqB,EAAC,GAAG,EAAE,KAAK,CAAC,CAAC;gBACxD,CAAC;gBAAC,OAAO,GAAG,EAAE,CAAC;oBACb,O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