@deliverd/sdk 0.38.0 → 0.39.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/README.md +18 -0
- package/dist/adapters/index.d.ts +2 -0
- package/dist/adapters/index.d.ts.map +1 -1
- package/dist/adapters/index.js +1 -0
- package/dist/adapters/muse-spark.d.ts +6 -0
- package/dist/adapters/muse-spark.d.ts.map +1 -1
- package/dist/adapters/muse-spark.js +7 -2
- package/dist/adapters/perplexity.d.ts +99 -0
- package/dist/adapters/perplexity.d.ts.map +1 -0
- package/dist/adapters/perplexity.js +150 -0
- package/dist/released.d.ts +1 -1
- package/dist/released.d.ts.map +1 -1
- package/dist/released.js +1555 -0
- package/package.json +1 -1
- package/src/adapters/index.ts +16 -0
- package/src/adapters/muse-spark.ts +9 -3
- package/src/adapters/perplexity.ts +236 -0
- package/src/released.ts +1556 -0
package/README.md
CHANGED
|
@@ -903,6 +903,24 @@ reason. For a wait longer than a process should stay up, let the run pause with
|
|
|
903
903
|
a `state` accessor, then `resolveOpenRouterApprovals(result, { deliverd })`
|
|
904
904
|
returns the `approveToolCalls` and `rejectToolCalls` to resume it with.
|
|
905
905
|
|
|
906
|
+
**Perplexity Agent API** — set `require_approval` on the MCP servers and connectors that can change something, and let Deliverd answer the run:
|
|
907
|
+
|
|
908
|
+
```ts
|
|
909
|
+
import { runPerplexityWithDeliverd } from "@deliverd/sdk/adapters";
|
|
910
|
+
|
|
911
|
+
const response = await runPerplexityWithDeliverd(perplexity, {
|
|
912
|
+
model: "openai/gpt-5.6-sol",
|
|
913
|
+
input: "Close the stale issues in our tracker",
|
|
914
|
+
tools: [{ type: "connector", id: "connector_linear", server_label: "linear", require_approval: "always" }],
|
|
915
|
+
}, { deliverd, approvers: ["platform-team"], run: runTool });
|
|
916
|
+
```
|
|
917
|
+
|
|
918
|
+
Each `mcp_approval_request` waits for a person and is answered with an
|
|
919
|
+
`mcp_approval_response` (a no carries their reason); with `run`, each of your
|
|
920
|
+
own `function_call`s runs only on a yes. Perplexity runs MCP calls without
|
|
921
|
+
asking unless `require_approval` is set. `replay: true` resends the
|
|
922
|
+
conversation for zero data retention accounts.
|
|
923
|
+
|
|
906
924
|
**Muse Spark** (Meta Model API) — the loop runs the calls, so hand them over with the function that runs them:
|
|
907
925
|
|
|
908
926
|
```ts
|
package/dist/adapters/index.d.ts
CHANGED
|
@@ -24,6 +24,8 @@ export { changeOpenRouterGuardrail, openRouterGuardrailForData, openRouterModels
|
|
|
24
24
|
export type { OpenRouterAdmin, OpenRouterChangeOptions, OpenRouterChangeResult, OpenRouterGuardrailSettings, OpenRouterModelUse, OpenRouterPolicyReading, RegisterClient, } from "./openrouter.js";
|
|
25
25
|
export { runMuseFunctionCalls, runMuseToolCalls } from "./muse-spark.js";
|
|
26
26
|
export type { MuseFunctionCall, MuseFunctionCallOutput, MuseToolApprovalOptions, MuseToolCall, MuseToolMessage, MuseToolRunner, } from "./muse-spark.js";
|
|
27
|
+
export { answerPerplexityApprovals, runPerplexityFunctionCalls, runPerplexityWithDeliverd, } from "./perplexity.js";
|
|
28
|
+
export type { PerplexityApprovalOptions, PerplexityApprovalRequest, PerplexityApprovalResponse, PerplexityApprovals, PerplexityClient, PerplexityFunctionCall, PerplexityFunctionCallOutput, PerplexityResponse, PerplexityRunOptions, } from "./perplexity.js";
|
|
27
29
|
export { deliverdAllow, deliverdWebMcpAllow, describeStep, uiSdkApprovalRoute, UI_SDK_DEFAULT_TIMEOUT } from "./ui-sdk.js";
|
|
28
30
|
export type { DeliverdAllowOptions, UiSdkApprovalAnswer, UiSdkApprovalRouteOptions, UiSdkAskContext, UiSdkStep } from "./ui-sdk.js";
|
|
29
31
|
export { defaultDescription, DEFAULT_TOOL_EXPIRY } from "./shared.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/adapters/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EAAE,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B,EAChB,sBAAsB,EACtB,4BAA4B,EAC5B,kBAAkB,EAClB,oBAAoB,GACrB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAE,YAAY,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAC3H,YAAY,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,yBAAyB,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACpI,OAAO,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AACtE,YAAY,EAAE,QAAQ,EAAE,eAAe,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/adapters/index.js
CHANGED
|
@@ -15,5 +15,6 @@ export { generateWithDeliverdApprovals, pendingMastraApproval, resolveMastraAppr
|
|
|
15
15
|
export { deliverdPermissionRequest, resolveOpenRouterApprovals } from "./openrouter.js";
|
|
16
16
|
export { changeOpenRouterGuardrail, openRouterGuardrailForData, openRouterModelsInUse, raiseOpenRouterKeyLimit, registerOpenRouterModels, } from "./openrouter.js";
|
|
17
17
|
export { runMuseFunctionCalls, runMuseToolCalls } from "./muse-spark.js";
|
|
18
|
+
export { answerPerplexityApprovals, runPerplexityFunctionCalls, runPerplexityWithDeliverd, } from "./perplexity.js";
|
|
18
19
|
export { deliverdAllow, deliverdWebMcpAllow, describeStep, uiSdkApprovalRoute, UI_SDK_DEFAULT_TIMEOUT } from "./ui-sdk.js";
|
|
19
20
|
export { defaultDescription, DEFAULT_TOOL_EXPIRY } from "./shared.js";
|
|
@@ -76,4 +76,10 @@ export declare function runMuseFunctionCalls(output: readonly {
|
|
|
76
76
|
export declare function runMuseToolCalls(message: {
|
|
77
77
|
tool_calls?: readonly MuseToolCall[] | null;
|
|
78
78
|
}, run: MuseToolRunner, options: MuseToolApprovalOptions): Promise<MuseToolMessage[]>;
|
|
79
|
+
/**
|
|
80
|
+
* Ask about one call when `when` selects it, and run it only on a yes. Shared
|
|
81
|
+
* with the other Responses-API-shaped adapters (Perplexity's Agent API), each
|
|
82
|
+
* keying its requests with its own prefix. Not exported from the adapters entry.
|
|
83
|
+
*/
|
|
84
|
+
export declare function approveAndRun(toolName: string, rawArguments: string, callId: string, run: MuseToolRunner, options: MuseToolApprovalOptions, prefix?: string): Promise<string>;
|
|
79
85
|
//# sourceMappingURL=muse-spark.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"muse-spark.d.ts","sourceRoot":"","sources":["../../src/adapters/muse-spark.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,KAAK,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAErE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH,MAAM,WAAW,uBAAwB,SAAQ,mBAAmB;IAClE;;;;OAIG;IACH,QAAQ,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,MAAM,EAAE,CAAC;CAC3E;AAED,6HAA6H;AAC7H,MAAM,MAAM,cAAc,GAAG,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,KAAK,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;AAE9F,8DAA8D;AAC9D,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,eAAe,CAAC;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,kEAAkE;AAClE,MAAM,WAAW,sBAAsB;IACrC,IAAI,EAAE,sBAAsB,CAAC;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,0EAA0E;AAC1E,MAAM,WAAW,YAAY;IAC3B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,CAAC,EAAE,MAAM,CAAC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}
|
|
@@ -26,7 +26,12 @@ export async function runMuseToolCalls(message, run, options) {
|
|
|
26
26
|
}
|
|
27
27
|
return results;
|
|
28
28
|
}
|
|
29
|
-
|
|
29
|
+
/**
|
|
30
|
+
* Ask about one call when `when` selects it, and run it only on a yes. Shared
|
|
31
|
+
* with the other Responses-API-shaped adapters (Perplexity's Agent API), each
|
|
32
|
+
* keying its requests with its own prefix. Not exported from the adapters entry.
|
|
33
|
+
*/
|
|
34
|
+
export async function approveAndRun(toolName, rawArguments, callId, run, options, prefix = "muse-spark:") {
|
|
30
35
|
const input = parseArguments(rawArguments);
|
|
31
36
|
if (!options.when || (await options.when(toolName, input))) {
|
|
32
37
|
const editable = typeof input === "object" && input !== null && !Array.isArray(input)
|
|
@@ -34,7 +39,7 @@ async function approveAndRun(toolName, rawArguments, callId, run, options) {
|
|
|
34
39
|
: undefined;
|
|
35
40
|
// The call id makes the ask idempotent: a loop that is retried, or a
|
|
36
41
|
// process restarted mid-wait, finds the request it already made.
|
|
37
|
-
const outcome = await askAboutCall(toolName, input,
|
|
42
|
+
const outcome = await askAboutCall(toolName, input, `${prefix}${callId}`, options, undefined, editable);
|
|
38
43
|
if (!outcome.allowed)
|
|
39
44
|
return outcome.reason;
|
|
40
45
|
// What was approved runs, which is the proposal unless a person corrected it.
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { type MuseToolApprovalOptions, type MuseToolRunner } from "./muse-spark.js";
|
|
2
|
+
/** An MCP or connector call waiting for an answer. It has not run. */
|
|
3
|
+
export interface PerplexityApprovalRequest {
|
|
4
|
+
type: "mcp_approval_request";
|
|
5
|
+
id: string;
|
|
6
|
+
name: string;
|
|
7
|
+
/** JSON-encoded on the wire. */
|
|
8
|
+
arguments?: string;
|
|
9
|
+
server_label?: string;
|
|
10
|
+
/** Set when the call came from a connector set up in the API Console. */
|
|
11
|
+
connector_id?: string | null;
|
|
12
|
+
}
|
|
13
|
+
/** The answer to one `mcp_approval_request`, sent as an `input` item of the next request. */
|
|
14
|
+
export interface PerplexityApprovalResponse {
|
|
15
|
+
type: "mcp_approval_response";
|
|
16
|
+
approval_request_id: string;
|
|
17
|
+
approve: boolean;
|
|
18
|
+
/** Read by the model when a call was declined. */
|
|
19
|
+
reason?: string;
|
|
20
|
+
}
|
|
21
|
+
export interface PerplexityApprovalOptions extends MuseToolApprovalOptions {
|
|
22
|
+
/** Put the person's reason on a declined answer, where the model reads it. Default true. */
|
|
23
|
+
sendReason?: boolean;
|
|
24
|
+
}
|
|
25
|
+
export interface PerplexityApprovals {
|
|
26
|
+
/** One answer per request, in the order they were asked: the next request's `input`. */
|
|
27
|
+
responses: PerplexityApprovalResponse[];
|
|
28
|
+
/** Why each declined call was declined, by request id, for your logs. */
|
|
29
|
+
reasons: Record<string, string>;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Ask about every `mcp_approval_request` in a response's `output`, and build
|
|
33
|
+
* the answers. A call `when` does not select is approved without asking.
|
|
34
|
+
* Other items are ignored.
|
|
35
|
+
*/
|
|
36
|
+
export declare function answerPerplexityApprovals(output: readonly {
|
|
37
|
+
type?: string;
|
|
38
|
+
}[] | null | undefined, options: PerplexityApprovalOptions): Promise<PerplexityApprovals>;
|
|
39
|
+
/** A function call the model asked for in an Agent API response. */
|
|
40
|
+
export interface PerplexityFunctionCall {
|
|
41
|
+
type: "function_call";
|
|
42
|
+
call_id: string;
|
|
43
|
+
name: string;
|
|
44
|
+
arguments: string;
|
|
45
|
+
}
|
|
46
|
+
/** The result of one function call, sent as an `input` item of the next request. */
|
|
47
|
+
export interface PerplexityFunctionCallOutput {
|
|
48
|
+
type: "function_call_output";
|
|
49
|
+
call_id: string;
|
|
50
|
+
output: string;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Ask about, and run, every `function_call` in a response's `output`. Only
|
|
54
|
+
* approved calls run; a declined one's output tells the model a person said
|
|
55
|
+
* no, and why. Every call gets an output, because the run cannot continue
|
|
56
|
+
* without one.
|
|
57
|
+
*/
|
|
58
|
+
export declare function runPerplexityFunctionCalls(output: readonly {
|
|
59
|
+
type?: string;
|
|
60
|
+
}[] | null | undefined, run: MuseToolRunner, options: PerplexityApprovalOptions): Promise<PerplexityFunctionCallOutput[]>;
|
|
61
|
+
/** Perplexity's client, or the OpenAI SDK pointed at `https://api.perplexity.ai/v1`. */
|
|
62
|
+
export interface PerplexityClient {
|
|
63
|
+
responses: {
|
|
64
|
+
create(params: Record<string, unknown>): Promise<PerplexityResponse> | PromiseLike<PerplexityResponse>;
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
/** The parts of an Agent API response this reads. */
|
|
68
|
+
export interface PerplexityResponse {
|
|
69
|
+
id: string;
|
|
70
|
+
status?: string;
|
|
71
|
+
output?: {
|
|
72
|
+
type?: string;
|
|
73
|
+
}[] | null;
|
|
74
|
+
}
|
|
75
|
+
export interface PerplexityRunOptions extends PerplexityApprovalOptions {
|
|
76
|
+
/** Makes your own function calls. Without it, a response asking for one is returned to you as it is. */
|
|
77
|
+
run?: MuseToolRunner;
|
|
78
|
+
/**
|
|
79
|
+
* Resend the conversation in `input` instead of chaining with
|
|
80
|
+
* `previous_response_id`. For accounts under zero data retention, which
|
|
81
|
+
* cannot use `previous_response_id`; each response's output, and the
|
|
82
|
+
* answers, are sent back unchanged.
|
|
83
|
+
*/
|
|
84
|
+
replay?: boolean;
|
|
85
|
+
/** Stop after this many rounds of answers. Default 10. */
|
|
86
|
+
maxRounds?: number;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Create a response, and keep answering its approval requests and running its
|
|
90
|
+
* function calls until it asks for nothing more.
|
|
91
|
+
*
|
|
92
|
+
* Each follow-up carries everything in `params` (`model`, `tools`,
|
|
93
|
+
* `instructions`) except `input`, which becomes the answers and outputs, with
|
|
94
|
+
* the last response's id as `previous_response_id`; or, with `replay`, the
|
|
95
|
+
* whole conversation so far. The `tools` array goes unchanged, as Perplexity
|
|
96
|
+
* requires. Non-streaming, foreground responses only.
|
|
97
|
+
*/
|
|
98
|
+
export declare function runPerplexityWithDeliverd(client: PerplexityClient, params: Record<string, unknown>, options: PerplexityRunOptions): Promise<PerplexityResponse>;
|
|
99
|
+
//# sourceMappingURL=perplexity.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"perplexity.d.ts","sourceRoot":"","sources":["../../src/adapters/perplexity.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,KAAK,uBAAuB,EAAE,KAAK,cAAc,EAAE,MAAM,iBAAiB,CAAC;AA0CnG,sEAAsE;AACtE,MAAM,WAAW,yBAAyB;IACxC,IAAI,EAAE,sBAAsB,CAAC;IAC7B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,gCAAgC;IAChC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,yEAAyE;IACzE,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC9B;AAED,6FAA6F;AAC7F,MAAM,WAAW,0BAA0B;IACzC,IAAI,EAAE,uBAAuB,CAAC;IAC9B,mBAAmB,EAAE,MAAM,CAAC;IAC5B,OAAO,EAAE,OAAO,CAAC;IACjB,kDAAkD;IAClD,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,yBAA0B,SAAQ,uBAAuB;IACxE,4FAA4F;IAC5F,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAED,MAAM,WAAW,mBAAmB;IAClC,wFAAwF;IACxF,SAAS,EAAE,0BAA0B,EAAE,CAAC;IACxC,yEAAyE;IACzE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACjC;AAED;;;;GAIG;AACH,wBAAsB,yBAAyB,CAC7C,MAAM,EAAE,SAAS;IAAE,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,EAAE,GAAG,IAAI,GAAG,SAAS,EACvD,OAAO,EAAE,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B,yBAAyB,CAC7C,MAAM,EAAE,gBAAgB,EACxB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC/B,OAAO,EAAE,oBAAoB,GAC5B,OAAO,CAAC,kBAAkB,CAAC,CAwB7B"}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { approveAndRun } from "./muse-spark.js";
|
|
2
|
+
import { askAboutCall } from "./shared.js";
|
|
3
|
+
/**
|
|
4
|
+
* Perplexity's Agent API: a person decides the tool calls a run asks to make.
|
|
5
|
+
*
|
|
6
|
+
* The Agent API (`POST https://api.perplexity.ai/v1/agent`, also served at
|
|
7
|
+
* `/v1/responses` for the OpenAI SDK) runs the agent loop itself: search,
|
|
8
|
+
* fetch, any model through one key, remote MCP servers and the connectors a
|
|
9
|
+
* Project administrator set up. It stops for a person in two places, and this
|
|
10
|
+
* answers both:
|
|
11
|
+
*
|
|
12
|
+
* - **MCP servers and connectors with `require_approval`.** The call does not
|
|
13
|
+
* run; the response's `output` carries an `mcp_approval_request` instead,
|
|
14
|
+
* and the next request answers it with an `mcp_approval_response`. Perplexity
|
|
15
|
+
* runs MCP and connector calls without asking unless `require_approval` is
|
|
16
|
+
* set, unlike OpenAI's default, so set it on every server that can change
|
|
17
|
+
* something.
|
|
18
|
+
* - **Your own functions.** A `function_call` in `output` is a call your code
|
|
19
|
+
* makes, so your code is where a person comes in: only approved calls run,
|
|
20
|
+
* and a declined one answers the model with the person's reason.
|
|
21
|
+
*
|
|
22
|
+
* ```ts
|
|
23
|
+
* import Perplexity from "@perplexity-ai/perplexity_ai";
|
|
24
|
+
* import { Deliverd } from "@deliverd/sdk";
|
|
25
|
+
* import { runPerplexityWithDeliverd } from "@deliverd/sdk/adapters";
|
|
26
|
+
*
|
|
27
|
+
* const response = await runPerplexityWithDeliverd(new Perplexity(), {
|
|
28
|
+
* model: "openai/gpt-5.6-sol",
|
|
29
|
+
* input: "Close the stale issues in our tracker",
|
|
30
|
+
* tools: [{ type: "connector", id: "connector_linear", server_label: "linear", require_approval: "always" }],
|
|
31
|
+
* }, { deliverd: new Deliverd(), approvers: ["platform-team"] });
|
|
32
|
+
* ```
|
|
33
|
+
*
|
|
34
|
+
* Every call is keyed by its id (`perplexity:<id>`), so a retried round, or a
|
|
35
|
+
* process restarted mid-wait, finds the request it already made. Shapes are
|
|
36
|
+
* from Perplexity's Agent API reference (MCP tool, connectors, custom
|
|
37
|
+
* functions); nothing from `@perplexity-ai/perplexity_ai` is imported.
|
|
38
|
+
*/
|
|
39
|
+
const PREFIX = "perplexity:";
|
|
40
|
+
/**
|
|
41
|
+
* Ask about every `mcp_approval_request` in a response's `output`, and build
|
|
42
|
+
* the answers. A call `when` does not select is approved without asking.
|
|
43
|
+
* Other items are ignored.
|
|
44
|
+
*/
|
|
45
|
+
export async function answerPerplexityApprovals(output, options) {
|
|
46
|
+
const result = { responses: [], reasons: {} };
|
|
47
|
+
for (const request of approvalRequests(output)) {
|
|
48
|
+
const input = parseArguments(request.arguments);
|
|
49
|
+
let approve = true;
|
|
50
|
+
let reason;
|
|
51
|
+
if (!options.when || (await options.when(request.name, input))) {
|
|
52
|
+
const outcome = await askAboutCall(request.name, input, `${PREFIX}${request.id}`, {
|
|
53
|
+
...options,
|
|
54
|
+
metadata: {
|
|
55
|
+
...options.metadata,
|
|
56
|
+
...(request.server_label ? { server: request.server_label } : {}),
|
|
57
|
+
...(request.connector_id ? { connector: request.connector_id } : {}),
|
|
58
|
+
},
|
|
59
|
+
});
|
|
60
|
+
approve = outcome.allowed;
|
|
61
|
+
if (!outcome.allowed)
|
|
62
|
+
reason = outcome.reason;
|
|
63
|
+
}
|
|
64
|
+
const answer = { type: "mcp_approval_response", approval_request_id: request.id, approve };
|
|
65
|
+
if (reason) {
|
|
66
|
+
result.reasons[request.id] = reason;
|
|
67
|
+
if (options.sendReason !== false)
|
|
68
|
+
answer.reason = reason;
|
|
69
|
+
}
|
|
70
|
+
result.responses.push(answer);
|
|
71
|
+
}
|
|
72
|
+
return result;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Ask about, and run, every `function_call` in a response's `output`. Only
|
|
76
|
+
* approved calls run; a declined one's output tells the model a person said
|
|
77
|
+
* no, and why. Every call gets an output, because the run cannot continue
|
|
78
|
+
* without one.
|
|
79
|
+
*/
|
|
80
|
+
export async function runPerplexityFunctionCalls(output, run, options) {
|
|
81
|
+
const results = [];
|
|
82
|
+
for (const item of output ?? []) {
|
|
83
|
+
if (item.type !== "function_call")
|
|
84
|
+
continue;
|
|
85
|
+
const call = item;
|
|
86
|
+
results.push({
|
|
87
|
+
type: "function_call_output",
|
|
88
|
+
call_id: call.call_id,
|
|
89
|
+
output: await approveAndRun(call.name, call.arguments, call.call_id, run, options, PREFIX),
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
return results;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Create a response, and keep answering its approval requests and running its
|
|
96
|
+
* function calls until it asks for nothing more.
|
|
97
|
+
*
|
|
98
|
+
* Each follow-up carries everything in `params` (`model`, `tools`,
|
|
99
|
+
* `instructions`) except `input`, which becomes the answers and outputs, with
|
|
100
|
+
* the last response's id as `previous_response_id`; or, with `replay`, the
|
|
101
|
+
* whole conversation so far. The `tools` array goes unchanged, as Perplexity
|
|
102
|
+
* requires. Non-streaming, foreground responses only.
|
|
103
|
+
*/
|
|
104
|
+
export async function runPerplexityWithDeliverd(client, params, options) {
|
|
105
|
+
const { input: firstInput, previous_response_id: _chain, ...carried } = params;
|
|
106
|
+
void _chain;
|
|
107
|
+
let response = await client.responses.create(params);
|
|
108
|
+
let history = toItems(firstInput);
|
|
109
|
+
const maxRounds = options.maxRounds ?? 10;
|
|
110
|
+
for (let round = 0;; round++) {
|
|
111
|
+
const output = response.output ?? [];
|
|
112
|
+
const asking = approvalRequests(output).length > 0;
|
|
113
|
+
const calling = !!options.run && output.some((item) => item.type === "function_call");
|
|
114
|
+
if (!asking && !calling)
|
|
115
|
+
return response;
|
|
116
|
+
if (round >= maxRounds) {
|
|
117
|
+
throw new Error(`The run was still asking for decisions after ${maxRounds} rounds. Raise maxRounds if that is expected.`);
|
|
118
|
+
}
|
|
119
|
+
const { responses } = await answerPerplexityApprovals(output, options);
|
|
120
|
+
const results = options.run ? await runPerplexityFunctionCalls(output, options.run, options) : [];
|
|
121
|
+
const answers = [...responses, ...results];
|
|
122
|
+
if (options.replay) {
|
|
123
|
+
history = [...history, ...output, ...answers];
|
|
124
|
+
response = await client.responses.create({ ...carried, input: history });
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
response = await client.responses.create({ ...carried, input: answers, previous_response_id: response.id });
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
function approvalRequests(output) {
|
|
132
|
+
return (output ?? []).filter((item) => item.type === "mcp_approval_request" && !!item.id);
|
|
133
|
+
}
|
|
134
|
+
function toItems(input) {
|
|
135
|
+
if (input === undefined || input === null)
|
|
136
|
+
return [];
|
|
137
|
+
if (typeof input === "string")
|
|
138
|
+
return [{ type: "message", role: "user", content: input }];
|
|
139
|
+
return Array.isArray(input) ? [...input] : [input];
|
|
140
|
+
}
|
|
141
|
+
function parseArguments(raw) {
|
|
142
|
+
if (!raw)
|
|
143
|
+
return {};
|
|
144
|
+
try {
|
|
145
|
+
return JSON.parse(raw);
|
|
146
|
+
}
|
|
147
|
+
catch {
|
|
148
|
+
return raw;
|
|
149
|
+
}
|
|
150
|
+
}
|
package/dist/released.d.ts
CHANGED
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
* **Add the version here when you publish it, not before.** An entry is a
|
|
44
44
|
* claim that `npm install @deliverd/sdk@x` works today.
|
|
45
45
|
*/
|
|
46
|
-
export declare const PUBLISHED_TO_NPM: readonly ["0.1.0", "0.2.0", "0.3.0", "0.4.0", "0.5.0", "0.6.0", "0.6.1", "0.6.2", "0.7.0", "0.7.1", "0.8.0", "0.8.1", "0.8.2", "0.9.0", "0.10.0", "0.11.0", "0.11.1", "0.12.0", "0.13.0", "0.14.0", "0.15.0", "0.16.0", "0.17.0", "0.18.0", "0.19.0", "0.20.0", "0.21.0", "0.22.0", "0.23.0", "0.24.0", "0.24.1", "0.25.0", "0.25.1", "0.26.0", "0.27.0", "0.28.0", "0.29.0", "0.30.0", "0.31.0", "0.32.0", "0.33.0", "0.34.0", "0.35.0", "0.36.0", "0.37.0"];
|
|
46
|
+
export declare const PUBLISHED_TO_NPM: readonly ["0.1.0", "0.2.0", "0.3.0", "0.4.0", "0.5.0", "0.6.0", "0.6.1", "0.6.2", "0.7.0", "0.7.1", "0.8.0", "0.8.1", "0.8.2", "0.9.0", "0.10.0", "0.11.0", "0.11.1", "0.12.0", "0.13.0", "0.14.0", "0.15.0", "0.16.0", "0.17.0", "0.18.0", "0.19.0", "0.20.0", "0.21.0", "0.22.0", "0.23.0", "0.24.0", "0.24.1", "0.25.0", "0.25.1", "0.26.0", "0.27.0", "0.28.0", "0.29.0", "0.30.0", "0.31.0", "0.32.0", "0.33.0", "0.34.0", "0.35.0", "0.36.0", "0.37.0", "0.38.0"];
|
|
47
47
|
/**
|
|
48
48
|
* A fingerprint of what each *published* version recorded.
|
|
49
49
|
*
|
package/dist/released.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"released.d.ts","sourceRoot":"","sources":["../src/released.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,gBAAgB
|
|
1
|
+
{"version":3,"file":"released.d.ts","sourceRoot":"","sources":["../src/released.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,gBAAgB,ycA+CnB,CAAC;AAEX;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CA2HzC,CAAC;AAEF,eAAO,MAAM,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAg9sCtD,CAAC"}
|