@github-tools/sdk 1.4.0 → 1.5.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 +25 -2
- package/dist/workflow.d.mts +98 -11
- package/dist/workflow.d.mts.map +1 -1
- package/dist/workflow.mjs +98 -5
- package/dist/workflow.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -365,7 +365,9 @@ All other `ToolLoopAgent` options (`stopWhen`, `toolChoice`, `onStepFinish`, etc
|
|
|
365
365
|
|
|
366
366
|
### `createDurableGithubAgent(options)`
|
|
367
367
|
|
|
368
|
-
Returns a `
|
|
368
|
+
Returns a `DurableGithubAgent` instance for use inside Vercel Workflow SDK functions. Every LLM call and tool execution runs as a durable step with automatic retries and crash recovery.
|
|
369
|
+
|
|
370
|
+
Supports both `.stream()` (real-time output to a writable) and `.generate()` (non-streaming, returns the full text response).
|
|
369
371
|
|
|
370
372
|
Requires the optional peer dependencies `workflow` and `@workflow/ai`:
|
|
371
373
|
|
|
@@ -373,6 +375,8 @@ Requires the optional peer dependencies `workflow` and `@workflow/ai`:
|
|
|
373
375
|
pnpm add workflow @workflow/ai
|
|
374
376
|
```
|
|
375
377
|
|
|
378
|
+
#### Streaming (chat UI)
|
|
379
|
+
|
|
376
380
|
```ts
|
|
377
381
|
import { createDurableGithubAgent } from '@github-tools/sdk/workflow'
|
|
378
382
|
import { getWritable } from 'workflow'
|
|
@@ -390,7 +394,26 @@ async function chatWorkflow(messages: ModelMessage[], token: string) {
|
|
|
390
394
|
}
|
|
391
395
|
```
|
|
392
396
|
|
|
393
|
-
|
|
397
|
+
#### Non-streaming (bot / background job — needs `"use step"`)
|
|
398
|
+
|
|
399
|
+
```ts
|
|
400
|
+
import { createGithubAgent } from '@github-tools/sdk'
|
|
401
|
+
|
|
402
|
+
async function agentTurn(prompt: string) {
|
|
403
|
+
"use step"
|
|
404
|
+
const agent = createGithubAgent({
|
|
405
|
+
model: 'anthropic/claude-sonnet-4.6',
|
|
406
|
+
preset: 'code-review',
|
|
407
|
+
requireApproval: false,
|
|
408
|
+
})
|
|
409
|
+
const { text } = await agent.generate({ prompt })
|
|
410
|
+
return text
|
|
411
|
+
}
|
|
412
|
+
```
|
|
413
|
+
|
|
414
|
+
> See [`examples/pr-review-bot`](../../examples/pr-review-bot) for a complete PR review bot built with Chat SDK and Vercel Workflow.
|
|
415
|
+
|
|
416
|
+
All presets (`code-review`, `issue-triage`, `ci-ops`, `repo-explorer`, `maintainer`) work with `createDurableGithubAgent`. Options mirror `createGithubAgent` with additional pass-through for `DurableAgentOptions` fields like `experimental_telemetry`, `onStepFinish`, `onFinish`, and `prepareStep`.
|
|
394
417
|
|
|
395
418
|
> **Note:** `requireApproval` is accepted but currently ignored by `DurableAgent` — the Workflow SDK does not yet support interactive tool approval.
|
|
396
419
|
|
package/dist/workflow.d.mts
CHANGED
|
@@ -1,10 +1,81 @@
|
|
|
1
|
-
import { n as createGithubAgent, t as CreateGithubAgentOptions } from "./agents-C6nqZiYp.mjs";
|
|
1
|
+
import { J as ToolOverrides, n as createGithubAgent, t as CreateGithubAgentOptions } from "./agents-C6nqZiYp.mjs";
|
|
2
2
|
import { ApprovalConfig, GithubToolPreset, GithubTools, GithubToolsOptions, GithubWriteToolName, createGithubTools } from "./index.mjs";
|
|
3
3
|
import * as ai from "ai";
|
|
4
|
-
import {
|
|
4
|
+
import { FinishReason, LanguageModelResponseMetadata, LanguageModelUsage, ModelMessage, StepResult, StopCondition, ToolSet } from "ai";
|
|
5
|
+
import { CompatibleLanguageModel, DurableAgentOptions, DurableAgentStreamOptions, DurableAgentStreamResult } from "@workflow/ai/agent";
|
|
5
6
|
|
|
6
7
|
//#region src/workflow.d.ts
|
|
7
|
-
|
|
8
|
+
/**
|
|
9
|
+
* Result of {@link DurableGithubAgent.generate}.
|
|
10
|
+
*/
|
|
11
|
+
interface DurableGithubAgentGenerateResult<TTools extends ToolSet = ToolSet> {
|
|
12
|
+
text: string;
|
|
13
|
+
finishReason: FinishReason;
|
|
14
|
+
usage: LanguageModelUsage;
|
|
15
|
+
steps: StepResult<TTools>[];
|
|
16
|
+
response: LanguageModelResponseMetadata & {
|
|
17
|
+
messages: ModelMessage[];
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* A wrapper around the Workflow SDK's `DurableAgent` that adds a non-streaming
|
|
22
|
+
* `.generate()` method alongside the existing `.stream()`.
|
|
23
|
+
*
|
|
24
|
+
* - `.stream()` — delegates to `DurableAgent.stream()`, each tool call is
|
|
25
|
+
* an individually retriable workflow step. Works in workflow context.
|
|
26
|
+
* - `.generate()` — uses `generateText` from the AI SDK for non-streaming
|
|
27
|
+
* execution. Must be called from within a `"use step"` function in
|
|
28
|
+
* workflow context (the Workflow runtime blocks raw I/O in workflow scope).
|
|
29
|
+
*/
|
|
30
|
+
declare class DurableGithubAgent<TTools extends ToolSet = ToolSet> {
|
|
31
|
+
private agent;
|
|
32
|
+
private _model;
|
|
33
|
+
private _instructions?;
|
|
34
|
+
private _telemetry?;
|
|
35
|
+
private _tools;
|
|
36
|
+
constructor(options: DurableAgentOptions<TTools>);
|
|
37
|
+
/** The tool set configured for this agent. */
|
|
38
|
+
get tools(): TTools;
|
|
39
|
+
/**
|
|
40
|
+
* Stream the agent's response. Delegates directly to `DurableAgent.stream()`.
|
|
41
|
+
* Works in workflow context — each tool call is a durable step.
|
|
42
|
+
*/
|
|
43
|
+
stream<TStreamTools extends TTools = TTools, OUTPUT = never, PARTIAL_OUTPUT = never>(options: DurableAgentStreamOptions<TStreamTools, OUTPUT, PARTIAL_OUTPUT>): Promise<DurableAgentStreamResult<TStreamTools, OUTPUT>>;
|
|
44
|
+
/**
|
|
45
|
+
* Generate a non-streaming response using `generateText` from the AI SDK.
|
|
46
|
+
*
|
|
47
|
+
* In workflow context this **must** be called from within a `"use step"`
|
|
48
|
+
* function, because the Workflow runtime blocks direct I/O (HTTP calls)
|
|
49
|
+
* at the workflow scope level.
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```ts
|
|
53
|
+
* async function agentTurn(prompt: string) {
|
|
54
|
+
* "use step"
|
|
55
|
+
* const agent = createDurableGithubAgent({
|
|
56
|
+
* model: 'anthropic/claude-sonnet-4.6',
|
|
57
|
+
* preset: 'code-review',
|
|
58
|
+
* })
|
|
59
|
+
* const { text } = await agent.generate({ prompt })
|
|
60
|
+
* return text
|
|
61
|
+
* }
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
generate({
|
|
65
|
+
prompt,
|
|
66
|
+
stopWhen
|
|
67
|
+
}: {
|
|
68
|
+
prompt: string;
|
|
69
|
+
stopWhen?: StopCondition<TTools> | Array<StopCondition<TTools>>;
|
|
70
|
+
}): Promise<DurableGithubAgentGenerateResult<TTools>>;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Options for creating a durable GitHub agent via {@link createDurableGithubAgent}.
|
|
74
|
+
*
|
|
75
|
+
* Extends all `DurableAgentOptions` (temperature, telemetry, callbacks, etc.)
|
|
76
|
+
* and adds GitHub-specific fields (token, preset, approval config).
|
|
77
|
+
*/
|
|
78
|
+
type CreateDurableGithubAgentOptions = Omit<DurableAgentOptions, 'model' | 'tools' | 'instructions'> & {
|
|
8
79
|
model: string | CompatibleLanguageModel | (() => Promise<CompatibleLanguageModel>);
|
|
9
80
|
/**
|
|
10
81
|
* GitHub personal access token.
|
|
@@ -14,21 +85,22 @@ type CreateDurableGithubAgentOptions = {
|
|
|
14
85
|
preset?: GithubToolPreset | GithubToolPreset[];
|
|
15
86
|
requireApproval?: ApprovalConfig;
|
|
16
87
|
instructions?: string;
|
|
17
|
-
additionalInstructions?: string;
|
|
18
|
-
maxSteps?: number;
|
|
19
|
-
temperature?: number;
|
|
88
|
+
additionalInstructions?: string;
|
|
20
89
|
};
|
|
21
90
|
/**
|
|
22
91
|
* Create a pre-configured durable GitHub agent powered by Vercel Workflow SDK's `DurableAgent`.
|
|
23
92
|
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
93
|
+
* Returns a {@link DurableGithubAgent} with two interaction modes:
|
|
94
|
+
*
|
|
95
|
+
* - `.stream()` — works directly in workflow scope; each tool call is a durable step.
|
|
96
|
+
* - `.generate()` — uses `generateText` from the AI SDK; must be called from
|
|
97
|
+
* within a `"use step"` function when running inside a workflow.
|
|
26
98
|
*
|
|
27
99
|
* **Note:** `requireApproval` is accepted for forward-compatibility but is currently
|
|
28
100
|
* ignored by `DurableAgent` — the Workflow SDK does not yet support interactive tool
|
|
29
101
|
* approval. All tools execute immediately without user confirmation.
|
|
30
102
|
*
|
|
31
|
-
* @example
|
|
103
|
+
* @example Streaming (chat UI — works in workflow scope)
|
|
32
104
|
* ```ts
|
|
33
105
|
* import { createDurableGithubAgent } from '@github-tools/sdk/workflow'
|
|
34
106
|
* import { getWritable } from 'workflow'
|
|
@@ -45,6 +117,21 @@ type CreateDurableGithubAgentOptions = {
|
|
|
45
117
|
* await agent.stream({ messages, writable })
|
|
46
118
|
* }
|
|
47
119
|
* ```
|
|
120
|
+
*
|
|
121
|
+
* @example Non-streaming (bot / background job — needs "use step")
|
|
122
|
+
* ```ts
|
|
123
|
+
* import { createDurableGithubAgent } from '@github-tools/sdk/workflow'
|
|
124
|
+
*
|
|
125
|
+
* async function agentTurn(prompt: string) {
|
|
126
|
+
* "use step"
|
|
127
|
+
* const agent = createDurableGithubAgent({
|
|
128
|
+
* model: 'anthropic/claude-sonnet-4.6',
|
|
129
|
+
* preset: 'code-review',
|
|
130
|
+
* })
|
|
131
|
+
* const { text } = await agent.generate({ prompt })
|
|
132
|
+
* return text
|
|
133
|
+
* }
|
|
134
|
+
* ```
|
|
48
135
|
*/
|
|
49
136
|
declare function createDurableGithubAgent({
|
|
50
137
|
model,
|
|
@@ -54,7 +141,7 @@ declare function createDurableGithubAgent({
|
|
|
54
141
|
instructions,
|
|
55
142
|
additionalInstructions,
|
|
56
143
|
...agentOptions
|
|
57
|
-
}: CreateDurableGithubAgentOptions):
|
|
144
|
+
}: CreateDurableGithubAgentOptions): DurableGithubAgent<Partial<{
|
|
58
145
|
getRepository: ai.Tool<{
|
|
59
146
|
owner: string;
|
|
60
147
|
repo: string;
|
|
@@ -723,5 +810,5 @@ declare function createDurableGithubAgent({
|
|
|
723
810
|
}>;
|
|
724
811
|
}>>;
|
|
725
812
|
//#endregion
|
|
726
|
-
export { type ApprovalConfig, CreateDurableGithubAgentOptions, type CreateGithubAgentOptions, type GithubToolPreset, type GithubTools, type GithubToolsOptions, type GithubWriteToolName, createDurableGithubAgent, createGithubAgent, createGithubTools };
|
|
813
|
+
export { type ApprovalConfig, CreateDurableGithubAgentOptions, type CreateGithubAgentOptions, DurableGithubAgent, DurableGithubAgentGenerateResult, type GithubToolPreset, type GithubTools, type GithubToolsOptions, type GithubWriteToolName, type ToolOverrides, createDurableGithubAgent, createGithubAgent, createGithubTools };
|
|
727
814
|
//# sourceMappingURL=workflow.d.mts.map
|
package/dist/workflow.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workflow.d.mts","names":[],"sources":["../src/workflow.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"workflow.d.mts","names":[],"sources":["../src/workflow.ts"],"mappings":";;;;;;;;;;UAUiB,gCAAA,gBAAgD,OAAA,GAAU,OAAA;EACzE,IAAA;EACA,YAAA,EAAc,YAAA;EACd,KAAA,EAAO,kBAAA;EACP,KAAA,EAAO,UAAA,CAAW,MAAA;EAClB,QAAA,EAAU,6BAAA;IAAkC,QAAA,EAAU,YAAA;EAAA;AAAA;;;;;;;;;;;cAa3C,kBAAA,gBAAkC,OAAA,GAAU,OAAA;EAAA,QAC/C,KAAA;EAAA,QACA,MAAA;EAAA,QACA,aAAA;EAAA,QACA,UAAA;EAAA,QACA,MAAA;cAEI,OAAA,EAAS,mBAAA,CAAoB,MAAA;EApB/B;EAAA,IA6BN,KAAA,CAAA,GAAS,MAAA;EA7ByC;;;AAaxD;EAwBE,MAAA,sBAA4B,MAAA,GAAS,MAAA,yCAAA,CACnC,OAAA,EAAS,yBAAA,CAA0B,YAAA,EAAc,MAAA,EAAQ,cAAA,IACxD,OAAA,CAAQ,wBAAA,CAAyB,YAAA,EAAc,MAAA;EA1BrB;;;;;;;;;;;;;;;;;;;;EAkDvB,QAAA,CAAA;IAAW,MAAA;IAAQ;EAAA;IAAc,MAAA;IAAgB,QAAA,GAAW,aAAA,CAAc,MAAA,IAAU,KAAA,CAAM,aAAA,CAAc,MAAA;EAAA,IAAa,OAAA,CAAQ,gCAAA,CAAiC,MAAA;AAAA;;;;;;;KAoC1J,+BAAA,GACV,IAAA,CAAK,mBAAA;EACH,KAAA,WAAgB,uBAAA,UAAiC,OAAA,CAAQ,uBAAA;EArFnD;;;;EA0FN,KAAA;EACA,MAAA,GAAS,gBAAA,GAAmB,gBAAA;EAC5B,eAAA,GAAkB,cAAA;EAClB,YAAA;EACA,sBAAA;AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAXJ;;;;;;;;;;;;;;;iBA4DgB,wBAAA,CAAA;EACd,KAAA;EACA,KAAA;EACA,MAAA;EACA,eAAA;EACA,YAAA;EACA,sBAAA;EAAA,GACG;AAAA,GACF,+BAAA,GAA+B,kBAAA,CAAA,OAAA;iBAAA,EAAA,CAAA,IAAA"}
|
package/dist/workflow.mjs
CHANGED
|
@@ -4,16 +4,94 @@ import { DurableAgent } from "@workflow/ai/agent";
|
|
|
4
4
|
|
|
5
5
|
//#region src/workflow.ts
|
|
6
6
|
/**
|
|
7
|
+
* A wrapper around the Workflow SDK's `DurableAgent` that adds a non-streaming
|
|
8
|
+
* `.generate()` method alongside the existing `.stream()`.
|
|
9
|
+
*
|
|
10
|
+
* - `.stream()` — delegates to `DurableAgent.stream()`, each tool call is
|
|
11
|
+
* an individually retriable workflow step. Works in workflow context.
|
|
12
|
+
* - `.generate()` — uses `generateText` from the AI SDK for non-streaming
|
|
13
|
+
* execution. Must be called from within a `"use step"` function in
|
|
14
|
+
* workflow context (the Workflow runtime blocks raw I/O in workflow scope).
|
|
15
|
+
*/
|
|
16
|
+
var DurableGithubAgent = class {
|
|
17
|
+
agent;
|
|
18
|
+
_model;
|
|
19
|
+
_instructions;
|
|
20
|
+
_telemetry;
|
|
21
|
+
_tools;
|
|
22
|
+
constructor(options) {
|
|
23
|
+
this.agent = new DurableAgent(options);
|
|
24
|
+
this._model = options.model;
|
|
25
|
+
this._instructions = options.instructions;
|
|
26
|
+
this._telemetry = options.experimental_telemetry;
|
|
27
|
+
this._tools = options.tools ?? {};
|
|
28
|
+
}
|
|
29
|
+
/** The tool set configured for this agent. */
|
|
30
|
+
get tools() {
|
|
31
|
+
return this.agent.tools;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Stream the agent's response. Delegates directly to `DurableAgent.stream()`.
|
|
35
|
+
* Works in workflow context — each tool call is a durable step.
|
|
36
|
+
*/
|
|
37
|
+
stream(options) {
|
|
38
|
+
return this.agent.stream(options);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Generate a non-streaming response using `generateText` from the AI SDK.
|
|
42
|
+
*
|
|
43
|
+
* In workflow context this **must** be called from within a `"use step"`
|
|
44
|
+
* function, because the Workflow runtime blocks direct I/O (HTTP calls)
|
|
45
|
+
* at the workflow scope level.
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```ts
|
|
49
|
+
* async function agentTurn(prompt: string) {
|
|
50
|
+
* "use step"
|
|
51
|
+
* const agent = createDurableGithubAgent({
|
|
52
|
+
* model: 'anthropic/claude-sonnet-4.6',
|
|
53
|
+
* preset: 'code-review',
|
|
54
|
+
* })
|
|
55
|
+
* const { text } = await agent.generate({ prompt })
|
|
56
|
+
* return text
|
|
57
|
+
* }
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
async generate({ prompt, stopWhen }) {
|
|
61
|
+
const { generateText } = await import("ai");
|
|
62
|
+
const model = typeof this._model === "function" ? await this._model() : this._model;
|
|
63
|
+
const system = typeof this._instructions === "string" ? this._instructions : void 0;
|
|
64
|
+
const result = await generateText({
|
|
65
|
+
model,
|
|
66
|
+
tools: this._tools,
|
|
67
|
+
system,
|
|
68
|
+
prompt,
|
|
69
|
+
stopWhen,
|
|
70
|
+
experimental_telemetry: this._telemetry
|
|
71
|
+
});
|
|
72
|
+
return {
|
|
73
|
+
text: result.text,
|
|
74
|
+
finishReason: result.finishReason,
|
|
75
|
+
usage: result.usage,
|
|
76
|
+
steps: result.steps,
|
|
77
|
+
response: result.response
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
/**
|
|
7
82
|
* Create a pre-configured durable GitHub agent powered by Vercel Workflow SDK's `DurableAgent`.
|
|
8
83
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
84
|
+
* Returns a {@link DurableGithubAgent} with two interaction modes:
|
|
85
|
+
*
|
|
86
|
+
* - `.stream()` — works directly in workflow scope; each tool call is a durable step.
|
|
87
|
+
* - `.generate()` — uses `generateText` from the AI SDK; must be called from
|
|
88
|
+
* within a `"use step"` function when running inside a workflow.
|
|
11
89
|
*
|
|
12
90
|
* **Note:** `requireApproval` is accepted for forward-compatibility but is currently
|
|
13
91
|
* ignored by `DurableAgent` — the Workflow SDK does not yet support interactive tool
|
|
14
92
|
* approval. All tools execute immediately without user confirmation.
|
|
15
93
|
*
|
|
16
|
-
* @example
|
|
94
|
+
* @example Streaming (chat UI — works in workflow scope)
|
|
17
95
|
* ```ts
|
|
18
96
|
* import { createDurableGithubAgent } from '@github-tools/sdk/workflow'
|
|
19
97
|
* import { getWritable } from 'workflow'
|
|
@@ -30,6 +108,21 @@ import { DurableAgent } from "@workflow/ai/agent";
|
|
|
30
108
|
* await agent.stream({ messages, writable })
|
|
31
109
|
* }
|
|
32
110
|
* ```
|
|
111
|
+
*
|
|
112
|
+
* @example Non-streaming (bot / background job — needs "use step")
|
|
113
|
+
* ```ts
|
|
114
|
+
* import { createDurableGithubAgent } from '@github-tools/sdk/workflow'
|
|
115
|
+
*
|
|
116
|
+
* async function agentTurn(prompt: string) {
|
|
117
|
+
* "use step"
|
|
118
|
+
* const agent = createDurableGithubAgent({
|
|
119
|
+
* model: 'anthropic/claude-sonnet-4.6',
|
|
120
|
+
* preset: 'code-review',
|
|
121
|
+
* })
|
|
122
|
+
* const { text } = await agent.generate({ prompt })
|
|
123
|
+
* return text
|
|
124
|
+
* }
|
|
125
|
+
* ```
|
|
33
126
|
*/
|
|
34
127
|
function createDurableGithubAgent({ model, token, preset, requireApproval, instructions, additionalInstructions, ...agentOptions }) {
|
|
35
128
|
const tools = createGithubTools({
|
|
@@ -38,7 +131,7 @@ function createDurableGithubAgent({ model, token, preset, requireApproval, instr
|
|
|
38
131
|
preset
|
|
39
132
|
});
|
|
40
133
|
const resolvedModel = typeof model === "string" || typeof model === "function" ? model : () => Promise.resolve(model);
|
|
41
|
-
return new
|
|
134
|
+
return new DurableGithubAgent({
|
|
42
135
|
...agentOptions,
|
|
43
136
|
model: resolvedModel,
|
|
44
137
|
tools,
|
|
@@ -51,5 +144,5 @@ function createDurableGithubAgent({ model, token, preset, requireApproval, instr
|
|
|
51
144
|
}
|
|
52
145
|
|
|
53
146
|
//#endregion
|
|
54
|
-
export { createDurableGithubAgent, createGithubAgent, createGithubTools };
|
|
147
|
+
export { DurableGithubAgent, createDurableGithubAgent, createGithubAgent, createGithubTools };
|
|
55
148
|
//# sourceMappingURL=workflow.mjs.map
|
package/dist/workflow.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workflow.mjs","names":[],"sources":["../src/workflow.ts"],"sourcesContent":["import { DurableAgent } from '@workflow/ai/agent'\nimport type { CompatibleLanguageModel } from '@workflow/ai/agent'\nimport { createGithubTools } from './index'\nimport { resolveInstructions } from './agents'\nimport type { GithubToolPreset, ApprovalConfig } from './index'\n\nexport
|
|
1
|
+
{"version":3,"file":"workflow.mjs","names":[],"sources":["../src/workflow.ts"],"sourcesContent":["import { DurableAgent } from '@workflow/ai/agent'\nimport type { CompatibleLanguageModel, DurableAgentOptions, DurableAgentStreamOptions, DurableAgentStreamResult, TelemetrySettings } from '@workflow/ai/agent'\nimport type { ToolSet, StepResult, FinishReason, LanguageModelUsage, LanguageModelResponseMetadata, ModelMessage, StopCondition } from 'ai'\nimport { createGithubTools } from './index'\nimport { resolveInstructions } from './agents'\nimport type { GithubToolPreset, ApprovalConfig } from './index'\n\n/**\n * Result of {@link DurableGithubAgent.generate}.\n */\nexport interface DurableGithubAgentGenerateResult<TTools extends ToolSet = ToolSet> {\n text: string\n finishReason: FinishReason\n usage: LanguageModelUsage\n steps: StepResult<TTools>[]\n response: LanguageModelResponseMetadata & { messages: ModelMessage[] }\n}\n\n/**\n * A wrapper around the Workflow SDK's `DurableAgent` that adds a non-streaming\n * `.generate()` method alongside the existing `.stream()`.\n *\n * - `.stream()` — delegates to `DurableAgent.stream()`, each tool call is\n * an individually retriable workflow step. Works in workflow context.\n * - `.generate()` — uses `generateText` from the AI SDK for non-streaming\n * execution. Must be called from within a `\"use step\"` function in\n * workflow context (the Workflow runtime blocks raw I/O in workflow scope).\n */\nexport class DurableGithubAgent<TTools extends ToolSet = ToolSet> {\n private agent: DurableAgent<TTools>\n private _model: DurableAgentOptions<TTools>['model']\n private _instructions?: DurableAgentOptions<TTools>['instructions']\n private _telemetry?: TelemetrySettings\n private _tools: TTools\n\n constructor(options: DurableAgentOptions<TTools>) {\n this.agent = new DurableAgent(options)\n this._model = options.model\n this._instructions = options.instructions\n this._telemetry = options.experimental_telemetry\n this._tools = options.tools ?? {} as TTools\n }\n\n /** The tool set configured for this agent. */\n get tools(): TTools {\n return this.agent.tools\n }\n\n /**\n * Stream the agent's response. Delegates directly to `DurableAgent.stream()`.\n * Works in workflow context — each tool call is a durable step.\n */\n stream<TStreamTools extends TTools = TTools, OUTPUT = never, PARTIAL_OUTPUT = never>(\n options: DurableAgentStreamOptions<TStreamTools, OUTPUT, PARTIAL_OUTPUT>,\n ): Promise<DurableAgentStreamResult<TStreamTools, OUTPUT>> {\n return this.agent.stream(options)\n }\n\n /**\n * Generate a non-streaming response using `generateText` from the AI SDK.\n *\n * In workflow context this **must** be called from within a `\"use step\"`\n * function, because the Workflow runtime blocks direct I/O (HTTP calls)\n * at the workflow scope level.\n *\n * @example\n * ```ts\n * async function agentTurn(prompt: string) {\n * \"use step\"\n * const agent = createDurableGithubAgent({\n * model: 'anthropic/claude-sonnet-4.6',\n * preset: 'code-review',\n * })\n * const { text } = await agent.generate({ prompt })\n * return text\n * }\n * ```\n */\n async generate({ prompt, stopWhen }: { prompt: string, stopWhen?: StopCondition<TTools> | Array<StopCondition<TTools>> }): Promise<DurableGithubAgentGenerateResult<TTools>> {\n const { generateText } = await import('ai')\n\n const model = typeof this._model === 'function'\n ? await this._model()\n : this._model\n\n const system = typeof this._instructions === 'string'\n ? this._instructions\n : undefined\n\n const result = await generateText({\n model: model as Parameters<typeof generateText>[0]['model'],\n tools: this._tools,\n system,\n prompt,\n stopWhen,\n experimental_telemetry: this._telemetry as Parameters<typeof generateText>[0]['experimental_telemetry'],\n })\n\n return {\n text: result.text,\n finishReason: result.finishReason,\n usage: result.usage,\n steps: result.steps as StepResult<TTools>[],\n response: result.response,\n }\n }\n}\n\n/**\n * Options for creating a durable GitHub agent via {@link createDurableGithubAgent}.\n *\n * Extends all `DurableAgentOptions` (temperature, telemetry, callbacks, etc.)\n * and adds GitHub-specific fields (token, preset, approval config).\n */\nexport type CreateDurableGithubAgentOptions =\n Omit<DurableAgentOptions, 'model' | 'tools' | 'instructions'> & {\n model: string | CompatibleLanguageModel | (() => Promise<CompatibleLanguageModel>)\n /**\n * GitHub personal access token.\n * Falls back to `process.env.GITHUB_TOKEN` when omitted.\n */\n token?: string\n preset?: GithubToolPreset | GithubToolPreset[]\n requireApproval?: ApprovalConfig\n instructions?: string\n additionalInstructions?: string\n }\n\n/**\n * Create a pre-configured durable GitHub agent powered by Vercel Workflow SDK's `DurableAgent`.\n *\n * Returns a {@link DurableGithubAgent} with two interaction modes:\n *\n * - `.stream()` — works directly in workflow scope; each tool call is a durable step.\n * - `.generate()` — uses `generateText` from the AI SDK; must be called from\n * within a `\"use step\"` function when running inside a workflow.\n *\n * **Note:** `requireApproval` is accepted for forward-compatibility but is currently\n * ignored by `DurableAgent` — the Workflow SDK does not yet support interactive tool\n * approval. All tools execute immediately without user confirmation.\n *\n * @example Streaming (chat UI — works in workflow scope)\n * ```ts\n * import { createDurableGithubAgent } from '@github-tools/sdk/workflow'\n * import { getWritable } from 'workflow'\n * import type { ModelMessage, UIMessageChunk } from 'ai'\n *\n * async function chatWorkflow(messages: ModelMessage[], token: string) {\n * \"use workflow\"\n * const agent = createDurableGithubAgent({\n * model: 'anthropic/claude-sonnet-4.6',\n * token,\n * preset: 'code-review',\n * })\n * const writable = getWritable<UIMessageChunk>()\n * await agent.stream({ messages, writable })\n * }\n * ```\n *\n * @example Non-streaming (bot / background job — needs \"use step\")\n * ```ts\n * import { createDurableGithubAgent } from '@github-tools/sdk/workflow'\n *\n * async function agentTurn(prompt: string) {\n * \"use step\"\n * const agent = createDurableGithubAgent({\n * model: 'anthropic/claude-sonnet-4.6',\n * preset: 'code-review',\n * })\n * const { text } = await agent.generate({ prompt })\n * return text\n * }\n * ```\n */\nexport function createDurableGithubAgent({\n model,\n token,\n preset,\n requireApproval,\n instructions,\n additionalInstructions,\n ...agentOptions\n}: CreateDurableGithubAgentOptions) {\n const tools = createGithubTools({ token, requireApproval, preset })\n\n const resolvedModel = typeof model === 'string' || typeof model === 'function'\n ? model\n : () => Promise.resolve(model)\n\n return new DurableGithubAgent({\n ...agentOptions as Omit<typeof agentOptions, 'toolChoice'>,\n model: resolvedModel,\n tools,\n instructions: resolveInstructions({ preset, instructions, additionalInstructions }),\n })\n}\n\nexport { createGithubTools, createGithubAgent } from './index'\nexport type { GithubTools, GithubToolsOptions, GithubToolPreset, GithubWriteToolName, ApprovalConfig, ToolOverrides } from './index'\nexport type { CreateGithubAgentOptions } from './agents'\n"],"mappings":";;;;;;;;;;;;;;;AA4BA,IAAa,qBAAb,MAAkE;CAChE,AAAQ;CACR,AAAQ;CACR,AAAQ;CACR,AAAQ;CACR,AAAQ;CAER,YAAY,SAAsC;AAChD,OAAK,QAAQ,IAAI,aAAa,QAAQ;AACtC,OAAK,SAAS,QAAQ;AACtB,OAAK,gBAAgB,QAAQ;AAC7B,OAAK,aAAa,QAAQ;AAC1B,OAAK,SAAS,QAAQ,SAAS,EAAE;;;CAInC,IAAI,QAAgB;AAClB,SAAO,KAAK,MAAM;;;;;;CAOpB,OACE,SACyD;AACzD,SAAO,KAAK,MAAM,OAAO,QAAQ;;;;;;;;;;;;;;;;;;;;;;CAuBnC,MAAM,SAAS,EAAE,QAAQ,YAAoJ;EAC3K,MAAM,EAAE,iBAAiB,MAAM,OAAO;EAEtC,MAAM,QAAQ,OAAO,KAAK,WAAW,aACjC,MAAM,KAAK,QAAQ,GACnB,KAAK;EAET,MAAM,SAAS,OAAO,KAAK,kBAAkB,WACzC,KAAK,gBACL;EAEJ,MAAM,SAAS,MAAM,aAAa;GACzB;GACP,OAAO,KAAK;GACZ;GACA;GACA;GACA,wBAAwB,KAAK;GAC9B,CAAC;AAEF,SAAO;GACL,MAAM,OAAO;GACb,cAAc,OAAO;GACrB,OAAO,OAAO;GACd,OAAO,OAAO;GACd,UAAU,OAAO;GAClB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsEL,SAAgB,yBAAyB,EACvC,OACA,OACA,QACA,iBACA,cACA,wBACA,GAAG,gBAC+B;CAClC,MAAM,QAAQ,kBAAkB;EAAE;EAAO;EAAiB;EAAQ,CAAC;CAEnE,MAAM,gBAAgB,OAAO,UAAU,YAAY,OAAO,UAAU,aAChE,cACM,QAAQ,QAAQ,MAAM;AAEhC,QAAO,IAAI,mBAAmB;EAC5B,GAAG;EACH,OAAO;EACP;EACA,cAAc,oBAAoB;GAAE;GAAQ;GAAc;GAAwB,CAAC;EACpF,CAAC"}
|
package/package.json
CHANGED