@spendgraph/tools 0.5.0 → 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/LICENSE +202 -0
- package/README.md +26 -258
- package/dist/agents/index.d.ts +1 -0
- package/dist/agents/index.js +1 -0
- package/dist/agents/moa/design.js +5 -0
- package/dist/agents/moa/http.js +1 -0
- package/dist/{builtin/write-document/write-document.d.ts → agents/moa/index.d.ts} +7 -2
- package/dist/agents/moa/index.js +1 -0
- package/dist/{builtin/write-document/commission.d.ts → agents/moa/moa.d.ts} +15 -15
- package/dist/agents/moa/moa.js +13 -0
- package/dist/{builtin/write-document → agents/moa}/types.d.ts +9 -9
- package/dist/agents/moa/types.js +0 -0
- package/dist/bogus/ask-mum.d.ts +5 -0
- package/dist/bogus/ask-mum.js +1 -0
- package/dist/bogus/book-taxi.d.ts +9 -0
- package/dist/bogus/book-taxi.js +1 -0
- package/dist/bogus/bus.d.ts +8 -0
- package/dist/bogus/bus.js +1 -0
- package/dist/bogus/calculator.d.ts +14 -0
- package/dist/bogus/calculator.js +1 -0
- package/dist/bogus/dictionary.d.ts +6 -0
- package/dist/bogus/dictionary.js +1 -0
- package/dist/bogus/feed-cat.d.ts +8 -0
- package/dist/bogus/feed-cat.js +1 -0
- package/dist/bogus/football-score.d.ts +6 -0
- package/dist/bogus/football-score.js +1 -0
- package/dist/bogus/gold-price.d.ts +7 -0
- package/dist/bogus/gold-price.js +1 -0
- package/dist/bogus/index.d.ts +14 -0
- package/dist/bogus/index.js +1 -0
- package/dist/bogus/my-calendar.d.ts +6 -0
- package/dist/bogus/my-calendar.js +1 -0
- package/dist/bogus/my-notes.d.ts +6 -0
- package/dist/bogus/my-notes.js +1 -0
- package/dist/bogus/my-recipes.d.ts +6 -0
- package/dist/bogus/my-recipes.js +1 -0
- package/dist/bogus/order-pizza.d.ts +12 -0
- package/dist/bogus/order-pizza.js +1 -0
- package/dist/bogus/prayer-times.d.ts +6 -0
- package/dist/bogus/prayer-times.js +1 -0
- package/dist/bogus/receipt.d.ts +8 -0
- package/dist/bogus/receipt.js +1 -0
- package/dist/builtin/calculate/calculate.d.ts +2 -0
- package/dist/builtin/calculate/calculate.js +1 -21
- package/dist/builtin/calculate/exact.d.ts +16 -0
- package/dist/builtin/calculate/exact.js +1 -0
- package/dist/builtin/calculate/index.d.ts +2 -1
- package/dist/builtin/calculate/index.js +1 -2
- package/dist/builtin/calculate/parse.js +1 -137
- package/dist/builtin/clock/clock.js +1 -61
- package/dist/builtin/clock/index.js +1 -1
- package/dist/builtin/code-exec/code-exec.d.ts +42 -0
- package/dist/builtin/code-exec/code-exec.js +1 -0
- package/dist/builtin/code-exec/index.d.ts +1 -0
- package/dist/builtin/code-exec/index.js +1 -0
- package/dist/builtin/date/date.d.ts +1 -1
- package/dist/builtin/date/date.js +1 -41
- package/dist/builtin/date/index.d.ts +1 -0
- package/dist/builtin/date/index.js +1 -2
- package/dist/builtin/date/shift.d.ts +1 -1
- package/dist/builtin/date/shift.js +1 -47
- package/dist/builtin/date/words.d.ts +13 -0
- package/dist/builtin/date/words.js +1 -0
- package/dist/builtin/decline/decline.d.ts +49 -0
- package/dist/builtin/decline/decline.js +1 -0
- package/dist/builtin/decline/index.d.ts +1 -0
- package/dist/builtin/decline/index.js +1 -0
- package/dist/builtin/escalate/escalate.d.ts +19 -0
- package/dist/builtin/escalate/escalate.js +1 -20
- package/dist/builtin/escalate/index.d.ts +1 -1
- package/dist/builtin/escalate/index.js +1 -1
- package/dist/builtin/extract/extract.d.ts +25 -0
- package/dist/builtin/extract/extract.js +1 -0
- package/dist/builtin/extract/index.d.ts +3 -0
- package/dist/builtin/extract/index.js +1 -0
- package/dist/builtin/extract/kinds.d.ts +6 -0
- package/dist/builtin/extract/kinds.js +1 -0
- package/dist/builtin/extract/readers.d.ts +7 -0
- package/dist/builtin/extract/readers.js +9 -0
- package/dist/builtin/finish/finish.d.ts +4 -0
- package/dist/builtin/finish/finish.js +1 -26
- package/dist/builtin/finish/index.js +1 -1
- package/dist/builtin/http/allow.d.ts +2 -0
- package/dist/builtin/http/allow.js +1 -37
- package/dist/builtin/http/hops.d.ts +10 -0
- package/dist/builtin/http/hops.js +1 -0
- package/dist/builtin/http/http.d.ts +9 -1
- package/dist/builtin/http/http.js +1 -41
- package/dist/builtin/http/index.d.ts +2 -0
- package/dist/builtin/http/index.js +1 -2
- package/dist/builtin/http/retry-after.d.ts +14 -0
- package/dist/builtin/http/retry-after.js +1 -0
- package/dist/builtin/index.d.ts +11 -6
- package/dist/builtin/index.js +1 -11
- package/dist/builtin/json/index.d.ts +1 -0
- package/dist/builtin/json/index.js +1 -2
- package/dist/builtin/json/json.js +1 -37
- package/dist/builtin/json/parse.d.ts +15 -0
- package/dist/builtin/json/parse.js +1 -0
- package/dist/builtin/json/path.js +1 -56
- package/dist/builtin/notes/index.d.ts +1 -0
- package/dist/builtin/notes/index.js +1 -0
- package/dist/builtin/notes/notes.d.ts +45 -0
- package/dist/builtin/notes/notes.js +2 -0
- package/dist/builtin/openalex/api.d.ts +22 -0
- package/dist/builtin/openalex/api.js +1 -0
- package/dist/builtin/openalex/index.d.ts +4 -0
- package/dist/builtin/openalex/index.js +1 -0
- package/dist/builtin/openalex/openalex.d.ts +23 -0
- package/dist/builtin/openalex/openalex.js +1 -0
- package/dist/builtin/openalex/render.d.ts +2 -0
- package/dist/builtin/openalex/render.js +4 -0
- package/dist/builtin/polite.d.ts +14 -0
- package/dist/builtin/polite.js +1 -0
- package/dist/builtin/publish/index.d.ts +1 -0
- package/dist/builtin/publish/index.js +1 -0
- package/dist/builtin/publish/publish.d.ts +46 -0
- package/dist/builtin/publish/publish.js +1 -0
- package/dist/builtin/think/index.js +1 -1
- package/dist/builtin/think/think.js +1 -12
- package/dist/builtin/web-search/index.js +1 -1
- package/dist/builtin/web-search/web-search.d.ts +10 -30
- package/dist/builtin/web-search/web-search.js +1 -103
- package/dist/builtin/wikidata/api.d.ts +40 -0
- package/dist/builtin/wikidata/api.js +1 -0
- package/dist/builtin/wikidata/index.d.ts +5 -0
- package/dist/builtin/wikidata/index.js +1 -0
- package/dist/builtin/wikidata/render.d.ts +13 -0
- package/dist/builtin/wikidata/render.js +2 -0
- package/dist/builtin/wikidata/wikidata.d.ts +21 -0
- package/dist/builtin/wikidata/wikidata.js +1 -0
- package/dist/bus/args.d.ts +11 -0
- package/dist/bus/args.js +1 -0
- package/dist/bus/bus.d.ts +23 -1
- package/dist/bus/bus.js +1 -49
- package/dist/bus/group.d.ts +21 -0
- package/dist/bus/group.js +1 -0
- package/dist/bus/index.d.ts +4 -0
- package/dist/bus/index.js +1 -2
- package/dist/bus/invoke.d.ts +1 -1
- package/dist/bus/invoke.js +3 -43
- package/dist/bus/namespace.d.ts +21 -0
- package/dist/bus/namespace.js +1 -0
- package/dist/bus/once.d.ts +32 -0
- package/dist/bus/once.js +1 -0
- package/dist/bus/only.d.ts +29 -0
- package/dist/bus/only.js +0 -0
- package/dist/bus/options.d.ts +31 -0
- package/dist/bus/options.js +0 -1
- package/dist/bus/output.d.ts +26 -0
- package/dist/bus/output.js +2 -0
- package/dist/bus/overlap.js +1 -31
- package/dist/bus/score.d.ts +11 -9
- package/dist/bus/score.js +1 -12
- package/dist/bus/select.d.ts +2 -17
- package/dist/bus/select.js +1 -44
- package/dist/bus/spent.d.ts +16 -0
- package/dist/bus/spent.js +1 -0
- package/dist/bus/step.js +1 -11
- package/dist/bus/terms.d.ts +25 -0
- package/dist/bus/terms.js +1 -0
- package/dist/bus/trace.d.ts +14 -1
- package/dist/bus/trace.js +1 -22
- package/dist/index.d.ts +16 -4
- package/dist/index.js +1 -3
- package/dist/internals.d.ts +9 -2
- package/dist/internals.js +1 -10
- package/dist/memories/client.d.ts +91 -0
- package/dist/memories/client.js +0 -0
- package/dist/memories/context.d.ts +5 -0
- package/dist/memories/context.js +1 -0
- package/dist/memories/deep-recall/deep-recall.d.ts +67 -0
- package/dist/memories/deep-recall/deep-recall.js +1 -0
- package/dist/memories/deep-recall/index.d.ts +1 -0
- package/dist/memories/deep-recall/index.js +1 -0
- package/dist/memories/explore/explore.d.ts +18 -0
- package/dist/memories/explore/explore.js +7 -0
- package/dist/memories/explore/subgraph.d.ts +12 -0
- package/dist/memories/explore/subgraph.js +3 -0
- package/dist/memories/index.d.ts +30 -0
- package/dist/memories/index.js +1 -0
- package/dist/memories/observe/observe.d.ts +7 -0
- package/dist/memories/observe/observe.js +1 -0
- package/dist/memories/recall/recall.d.ts +42 -0
- package/dist/memories/recall/recall.js +1 -0
- package/dist/memories/recall/render.d.ts +5 -0
- package/dist/memories/recall/render.js +3 -0
- package/dist/memories/remember/remember.d.ts +49 -0
- package/dist/memories/remember/remember.js +1 -0
- package/dist/search/index.d.ts +5 -0
- package/dist/search/index.js +1 -0
- package/dist/search/retry.d.ts +6 -0
- package/dist/search/retry.js +1 -0
- package/dist/search/search.d.ts +63 -0
- package/dist/search/search.js +1 -0
- package/dist/search/searxng/index.d.ts +2 -0
- package/dist/search/searxng/index.js +1 -0
- package/dist/search/searxng/searxng.d.ts +14 -0
- package/dist/search/searxng/searxng.js +5 -0
- package/dist/search/searxng/text.d.ts +2 -0
- package/dist/search/searxng/text.js +3 -0
- package/dist/search/sonar/index.d.ts +2 -0
- package/dist/search/sonar/index.js +1 -0
- package/dist/search/sonar/reply.js +1 -0
- package/dist/search/sonar/sonar.d.ts +13 -0
- package/dist/search/sonar/sonar.js +1 -0
- package/dist/search/tavily/index.d.ts +4 -0
- package/dist/search/tavily/index.js +1 -0
- package/dist/search/tavily/reply.d.ts +22 -0
- package/dist/search/tavily/reply.js +5 -0
- package/dist/search/tavily/tavily.d.ts +14 -0
- package/dist/search/tavily/tavily.js +1 -0
- package/dist/testing/index.d.ts +2 -0
- package/dist/testing/index.js +1 -0
- package/dist/testing/replay.d.ts +55 -0
- package/dist/testing/replay.js +1 -0
- package/dist/testing/store.d.ts +35 -0
- package/dist/testing/store.js +4 -0
- package/dist/tool/bind.js +1 -64
- package/dist/tool/index.js +1 -2
- package/dist/tool/tool.d.ts +5 -1
- package/dist/tool/tool.js +1 -51
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.js +0 -1
- package/dist/types/result.d.ts +38 -0
- package/dist/types/result.js +0 -1
- package/dist/types/tool.d.ts +74 -0
- package/dist/types/tool.js +0 -1
- package/dist/wire/index.js +1 -3
- package/dist/wire/json-schema.js +1 -65
- package/dist/wire/markdown.d.ts +5 -3
- package/dist/wire/markdown.js +9 -29
- package/dist/wire/providers.js +1 -18
- package/docs/bogus.mdx +85 -0
- package/docs/builtins.mdx +156 -0
- package/docs/bus.mdx +90 -0
- package/docs/declaring.mdx +85 -0
- package/docs/effects.mdx +49 -0
- package/docs/overview.mdx +76 -0
- package/docs/selecting.mdx +79 -0
- package/docs/stored.mdx +83 -0
- package/docs/turns.mdx +57 -0
- package/package.json +28 -11
- package/dist/builtin/deep-recall/deep-recall.d.ts +0 -27
- package/dist/builtin/deep-recall/deep-recall.js +0 -45
- package/dist/builtin/deep-recall/index.d.ts +0 -1
- package/dist/builtin/deep-recall/index.js +0 -1
- package/dist/builtin/web-search/reply.js +0 -27
- package/dist/builtin/write-document/commission.js +0 -152
- package/dist/builtin/write-document/design.js +0 -86
- package/dist/builtin/write-document/http.js +0 -71
- package/dist/builtin/write-document/index.d.ts +0 -6
- package/dist/builtin/write-document/index.js +0 -4
- package/dist/builtin/write-document/types.js +0 -1
- package/dist/builtin/write-document/write-document.js +0 -142
- /package/dist/{builtin/write-document → agents/moa}/design.d.ts +0 -0
- /package/dist/{builtin/write-document → agents/moa}/http.d.ts +0 -0
- /package/dist/{builtin/web-search → search/sonar}/reply.d.ts +0 -0
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
export const MOA_BASE_URL = "https://api.fnmoa.com";
|
|
2
|
-
const DEFAULT_REQUEST_TIMEOUT_MS = 60_000;
|
|
3
|
-
const ERROR_DETAIL_CHARS = 500;
|
|
4
|
-
export class MoaApiError extends Error {
|
|
5
|
-
status;
|
|
6
|
-
detail;
|
|
7
|
-
constructor(message, status, detail) {
|
|
8
|
-
super(detail ? `${message}: ${detail}` : message);
|
|
9
|
-
this.name = "MoaApiError";
|
|
10
|
-
this.status = status;
|
|
11
|
-
this.detail = detail;
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
function reasonOf(err) {
|
|
15
|
-
const cause = err.cause;
|
|
16
|
-
return cause?.code ?? cause?.message ?? err.message;
|
|
17
|
-
}
|
|
18
|
-
function deadlineSignal(timeoutMs, caller) {
|
|
19
|
-
const controller = new AbortController();
|
|
20
|
-
const stop = () => controller.abort();
|
|
21
|
-
let expired = false;
|
|
22
|
-
const timer = setTimeout(() => {
|
|
23
|
-
expired = true;
|
|
24
|
-
stop();
|
|
25
|
-
}, timeoutMs);
|
|
26
|
-
caller?.addEventListener("abort", stop, { once: true });
|
|
27
|
-
if (caller?.aborted)
|
|
28
|
-
stop();
|
|
29
|
-
return {
|
|
30
|
-
signal: controller.signal,
|
|
31
|
-
expired: () => expired,
|
|
32
|
-
release: () => {
|
|
33
|
-
clearTimeout(timer);
|
|
34
|
-
caller?.removeEventListener("abort", stop);
|
|
35
|
-
},
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
export function createRequest(config = {}) {
|
|
39
|
-
const doFetch = config.fetch ?? globalThis.fetch.bind(globalThis);
|
|
40
|
-
const base = (config.baseUrl ?? MOA_BASE_URL).replace(/\/+$/, "");
|
|
41
|
-
return async function request(path, opts = {}) {
|
|
42
|
-
const timeoutMs = opts.timeoutMs ?? config.timeoutMs ?? DEFAULT_REQUEST_TIMEOUT_MS;
|
|
43
|
-
const method = opts.method ?? "GET";
|
|
44
|
-
const url = `${base}${path}`;
|
|
45
|
-
const { signal, expired, release } = deadlineSignal(timeoutMs, opts.signal);
|
|
46
|
-
try {
|
|
47
|
-
const res = await doFetch(url, {
|
|
48
|
-
method,
|
|
49
|
-
signal,
|
|
50
|
-
headers: {
|
|
51
|
-
...(config.apiKey ? { authorization: `Bearer ${config.apiKey}` } : {}),
|
|
52
|
-
...(opts.body === undefined ? {} : { "content-type": "application/json" }),
|
|
53
|
-
},
|
|
54
|
-
...(opts.body === undefined ? {} : { body: JSON.stringify(opts.body) }),
|
|
55
|
-
}).catch((err) => {
|
|
56
|
-
if (opts.signal?.aborted)
|
|
57
|
-
throw err;
|
|
58
|
-
if (expired())
|
|
59
|
-
throw new MoaApiError(`Moa did not answer ${method} ${path}`, 504, `${timeoutMs}ms`);
|
|
60
|
-
throw new MoaApiError(`Moa is unreachable at ${url}`, 0, reasonOf(err));
|
|
61
|
-
});
|
|
62
|
-
if (!res.ok) {
|
|
63
|
-
throw new MoaApiError(`Moa returned ${res.status} for ${method} ${path}`, res.status, (await res.text()).slice(0, ERROR_DETAIL_CHARS));
|
|
64
|
-
}
|
|
65
|
-
return res.status === 204 ? undefined : (await res.json());
|
|
66
|
-
}
|
|
67
|
-
finally {
|
|
68
|
-
release();
|
|
69
|
-
}
|
|
70
|
-
};
|
|
71
|
-
}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
export type { CommissionClient, PollOptions } from "./commission.js";
|
|
2
|
-
export { CommissionAbortedError, CommissionTimeoutError, createCommissionClient, INTERACTIVE_TIMEOUT_MS, pollUntilDone, } from "./commission.js";
|
|
3
|
-
export { DEFAULT_DESIGN, type DesignGuide, mergeDesign, renderDesign } from "./design.js";
|
|
4
|
-
export { MOA_BASE_URL, MoaApiError, type MoaClientConfig } from "./http.js";
|
|
5
|
-
export type { ArtifactFormat, CommissionArtifact, CommissionInput, CommissionResult, CommissionStatus, } from "./types.js";
|
|
6
|
-
export { type WriteDocumentOptions, writeDocument } from "./write-document.js";
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
export { CommissionAbortedError, CommissionTimeoutError, createCommissionClient, INTERACTIVE_TIMEOUT_MS, pollUntilDone, } from "./commission.js";
|
|
2
|
-
export { DEFAULT_DESIGN, mergeDesign, renderDesign } from "./design.js";
|
|
3
|
-
export { MOA_BASE_URL, MoaApiError } from "./http.js";
|
|
4
|
-
export { writeDocument } from "./write-document.js";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
import { tool } from "../../tool/index.js";
|
|
2
|
-
import { CommissionAbortedError, CommissionTimeoutError, createCommissionClient, pollUntilDone, } from "./commission.js";
|
|
3
|
-
import { DEFAULT_DESIGN, mergeDesign, renderDesign } from "./design.js";
|
|
4
|
-
const ALL_FORMATS = ["pdf", "pptx", "docx", "md"];
|
|
5
|
-
const DEFAULT_TIMEOUT_MS = 600_000;
|
|
6
|
-
const DEFAULT_SETTLE_MS = 2_000;
|
|
7
|
-
const DEFAULT_MAX_CHARS = 4_000;
|
|
8
|
-
function describe(formats, design) {
|
|
9
|
-
return ("Commissions a document agent to write and render a finished file — " +
|
|
10
|
-
`${formats.map((f) => `.${f}`).join(", ")} — and hands back where to download it. Use it ` +
|
|
11
|
-
"when the answer has to be a document somebody opens: a report, a deck, a proposal, a " +
|
|
12
|
-
"one-pager. Not for text you can simply write in your reply. It runs for minutes and it " +
|
|
13
|
-
`costs money, so brief it once and brief it fully — the agent cannot see this ` +
|
|
14
|
-
"conversation, so every fact, figure and quote it must use goes in `source`. Design is " +
|
|
15
|
-
`already settled by ${design.name ?? "the house style"}; use \`design_notes\` only for what ` +
|
|
16
|
-
"this one document must do differently.");
|
|
17
|
-
}
|
|
18
|
-
function delivered(result, style, maxChars, includeData) {
|
|
19
|
-
const documents = (result.artifacts ?? []).map((a) => ({
|
|
20
|
-
name: a.name,
|
|
21
|
-
format: a.format,
|
|
22
|
-
url: a.url,
|
|
23
|
-
mime: a.mime,
|
|
24
|
-
sizeBytes: a.sizeBytes,
|
|
25
|
-
...(includeData && a.data ? { data: a.data } : {}),
|
|
26
|
-
}));
|
|
27
|
-
return {
|
|
28
|
-
taskId: result.id,
|
|
29
|
-
sessionId: result.sessionId,
|
|
30
|
-
status: "done",
|
|
31
|
-
style,
|
|
32
|
-
documents,
|
|
33
|
-
delivered: documents.length > 0,
|
|
34
|
-
writeUp: result.output?.slice(0, maxChars),
|
|
35
|
-
truncated: (result.output?.length ?? 0) > maxChars,
|
|
36
|
-
turns: result.numTurns,
|
|
37
|
-
costMicroUsd: result.costUsd === undefined ? undefined : Math.round(result.costUsd * 1_000_000),
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
function stillRendering(id, style, err) {
|
|
41
|
-
return {
|
|
42
|
-
taskId: id,
|
|
43
|
-
status: "running",
|
|
44
|
-
style,
|
|
45
|
-
documents: [],
|
|
46
|
-
delivered: false,
|
|
47
|
-
note: `Still rendering after ${Math.round(err.timeoutMs / 1000)}s. The task is not lost — ` +
|
|
48
|
-
"say so rather than commissioning it again.",
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
export function writeDocument(opts) {
|
|
52
|
-
if (!opts.client && !opts.apiKey?.trim()) {
|
|
53
|
-
throw new Error("writeDocument needs a Moa apiKey; it will not read one from the process.");
|
|
54
|
-
}
|
|
55
|
-
const allowed = opts.formats?.length ? opts.formats : ALL_FORMATS;
|
|
56
|
-
const design = mergeDesign(DEFAULT_DESIGN, opts.design);
|
|
57
|
-
const maxChars = opts.maxChars ?? DEFAULT_MAX_CHARS;
|
|
58
|
-
const client = opts.client ??
|
|
59
|
-
createCommissionClient({
|
|
60
|
-
apiKey: opts.apiKey,
|
|
61
|
-
baseUrl: opts.baseUrl,
|
|
62
|
-
...(opts.fetch ? { fetch: opts.fetch } : {}),
|
|
63
|
-
});
|
|
64
|
-
return tool({
|
|
65
|
-
name: "write_document",
|
|
66
|
-
description: describe(allowed, design),
|
|
67
|
-
effect: "destructive",
|
|
68
|
-
args: [
|
|
69
|
-
{
|
|
70
|
-
name: "brief",
|
|
71
|
-
type: "text",
|
|
72
|
-
required: true,
|
|
73
|
-
maxLength: 8000,
|
|
74
|
-
description: "What to produce, who reads it, what it must cover and how long it runs. Write it " +
|
|
75
|
-
"as you would brief a person who knows the craft and nothing about this account.",
|
|
76
|
-
},
|
|
77
|
-
{
|
|
78
|
-
name: "format",
|
|
79
|
-
type: "enum",
|
|
80
|
-
required: true,
|
|
81
|
-
options: ["pdf", "pptx", "docx", "md"],
|
|
82
|
-
description: "pptx for anything presented, pdf for anything sent, docx for anything edited.",
|
|
83
|
-
},
|
|
84
|
-
{
|
|
85
|
-
name: "source",
|
|
86
|
-
type: "text",
|
|
87
|
-
required: false,
|
|
88
|
-
maxLength: 40000,
|
|
89
|
-
description: "The material it must build from — figures, findings, quotes, an outline — verbatim. " +
|
|
90
|
-
"Anything missing here the agent will either omit or invent.",
|
|
91
|
-
},
|
|
92
|
-
{
|
|
93
|
-
name: "design_notes",
|
|
94
|
-
type: "text",
|
|
95
|
-
required: false,
|
|
96
|
-
maxLength: 2000,
|
|
97
|
-
description: "How this one document departs from the house style, in plain words. Leave it empty " +
|
|
98
|
-
"unless the user asked for something specific.",
|
|
99
|
-
},
|
|
100
|
-
{
|
|
101
|
-
name: "session_id",
|
|
102
|
-
type: "string",
|
|
103
|
-
required: false,
|
|
104
|
-
description: "Continue an earlier write_document instead of starting over — take it from that " +
|
|
105
|
-
"result's sessionId. Use it to revise a document or to recast one into another format.",
|
|
106
|
-
},
|
|
107
|
-
],
|
|
108
|
-
run: async ({ brief, format, source, design_notes, session_id }) => {
|
|
109
|
-
if (!allowed.includes(format)) {
|
|
110
|
-
throw new Error(`write_document was asked for .${format}, which this deployment does not produce ` +
|
|
111
|
-
`(${allowed.map((f) => `.${f}`).join(", ")}).`);
|
|
112
|
-
}
|
|
113
|
-
const id = await client.create({
|
|
114
|
-
task: brief,
|
|
115
|
-
context: source,
|
|
116
|
-
design: renderDesign(design, format, design_notes),
|
|
117
|
-
artifacts: [format],
|
|
118
|
-
...(session_id ? { sessionId: session_id } : {}),
|
|
119
|
-
});
|
|
120
|
-
try {
|
|
121
|
-
const result = await pollUntilDone(client, id, {
|
|
122
|
-
timeoutMs: opts.timeoutMs ?? DEFAULT_TIMEOUT_MS,
|
|
123
|
-
settleMs: DEFAULT_SETTLE_MS,
|
|
124
|
-
expectArtifacts: true,
|
|
125
|
-
...(opts.signal ? { signal: opts.signal } : {}),
|
|
126
|
-
});
|
|
127
|
-
if (result.status === "failed") {
|
|
128
|
-
throw new Error(`write_document: Moa task ${id} failed: ${result.error ?? "no reason given"}`);
|
|
129
|
-
}
|
|
130
|
-
return delivered(result, design.name, maxChars, opts.includeData === true);
|
|
131
|
-
}
|
|
132
|
-
catch (err) {
|
|
133
|
-
if (err instanceof CommissionAbortedError && opts.cancelOnAbort !== false) {
|
|
134
|
-
await client.cancel?.(id).catch(() => undefined);
|
|
135
|
-
}
|
|
136
|
-
if (err instanceof CommissionTimeoutError)
|
|
137
|
-
return stillRendering(id, design.name, err);
|
|
138
|
-
throw err;
|
|
139
|
-
}
|
|
140
|
-
},
|
|
141
|
-
});
|
|
142
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|