libfx 0.0.13 → 0.0.14
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 +454 -486
- package/browser.js +18 -4
- package/chatgpt-sign-in.js +141 -0
- package/chatgpt.js +69 -0
- package/custom-provider.js +123 -0
- package/durable/local.mjs +190 -0
- package/durable/vercel.mjs +268 -0
- package/durable/world.mjs +1 -0
- package/durable.js +2752 -0
- package/fetch-cleanup.js +12 -0
- package/fx-core.wasm +0 -0
- package/fx-harness.js +220 -0
- package/fx-sdk.js +1302 -116
- package/fx-term.wasm +0 -0
- package/grok-sign-in.js +145 -0
- package/grok.js +108 -0
- package/libfx.darwin-arm64.node +0 -0
- package/libfx.darwin-x64.node +0 -0
- package/libfx.linux-arm64.node +0 -0
- package/libfx.linux-x64.node +0 -0
- package/mcp.js +14 -2
- package/node.cjs +4508 -213
- package/node.js +195 -47
- package/oauth.js +64 -0
- package/package.json +66 -13
- package/subscription.js +253 -0
- package/tool-observation.js +185 -0
- package/types/browser.d.ts +146 -0
- package/types/chatgpt.d.ts +58 -0
- package/types/durable-local.d.ts +18 -0
- package/types/durable-vercel.d.ts +22 -0
- package/types/durable-world.d.ts +95 -0
- package/types/grok.d.ts +61 -0
- package/types/libfx.d.cts +1061 -0
- package/types/mcp.d.ts +46 -0
- package/types/node.d.cts +165 -0
- package/types/node.d.ts +3 -0
- package/types/skills-node.d.ts +25 -0
- package/types/skills.d.ts +28 -0
- package/types/wasm.d.ts +106 -0
package/types/mcp.d.ts
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// `libfx/mcp` (mcp.js): tools and instructions from a host-owned MCP client.
|
|
2
|
+
import type { FxAgentHostTool } from "./libfx.cjs";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The parts of an MCP client the adapter calls, with the MCP TypeScript SDK
|
|
6
|
+
* v1 signatures. Transport, authentication, elicitation, and cleanup stay
|
|
7
|
+
* with the host.
|
|
8
|
+
*/
|
|
9
|
+
export interface McpClient {
|
|
10
|
+
/** Resolves to the tools array or `{ tools, nextCursor? }`. */
|
|
11
|
+
listTools(params?: { cursor: string }): unknown;
|
|
12
|
+
/** Called with the tool's original name, the model's arguments, and the turn's `signal` in `options`. */
|
|
13
|
+
callTool(params: { name: string; arguments?: unknown; _meta?: { "libfx/correlationId": string } }, resultSchema?: unknown, options?: { signal?: AbortSignal }): unknown;
|
|
14
|
+
getServerVersion?(): { name?: string } | undefined;
|
|
15
|
+
/** Required when `resources` is given. */
|
|
16
|
+
readResource?(params: { uri: string }): unknown;
|
|
17
|
+
/** Required when `prompts` is given. */
|
|
18
|
+
getPrompt?(params: { name: string; arguments?: Record<string, string> }): unknown;
|
|
19
|
+
close?(): unknown;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** Options for `createMcpAdapter()`. */
|
|
23
|
+
export interface McpAdapterOptions {
|
|
24
|
+
/** Local server identity for hook events. Defaults to the client's reported server name, or null. */
|
|
25
|
+
serverName?: string;
|
|
26
|
+
/** Send an opaque UUID as `_meta["libfx/correlationId"]`. Default false; doesn't request MCP progress notifications. */
|
|
27
|
+
propagateCorrelation?: boolean;
|
|
28
|
+
/** Prepended to each tool name: letters, digits, `_`, or `-`. */
|
|
29
|
+
prefix?: string;
|
|
30
|
+
/** Resource URIs whose text becomes instructions. */
|
|
31
|
+
resources?: readonly string[];
|
|
32
|
+
/** Prompts whose text becomes instructions: a name, or a `getPrompt()` request. */
|
|
33
|
+
prompts?: readonly (string | { name: string; arguments?: Record<string, string> })[];
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** What `createMcpAdapter()` resolves to. Pass `tools` and `instructions` to the agent. */
|
|
37
|
+
export interface McpAdapter {
|
|
38
|
+
/** Each tool has `idempotent: false`; set it to `true` on a tool known to be safe to run twice. */
|
|
39
|
+
tools: FxAgentHostTool[];
|
|
40
|
+
instructions: string;
|
|
41
|
+
/** Closes the client once. */
|
|
42
|
+
close(): Promise<void>;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** Adapts a host-owned MCP client into agent tools and instructions. */
|
|
46
|
+
export declare function createMcpAdapter(client: McpClient, options?: McpAdapterOptions): Promise<McpAdapter>;
|
package/types/node.d.cts
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
// `libfx` and `libfx/node` on Node.js, for `require` (node.cjs). The ESM entry,
|
|
2
|
+
// node.d.ts, re-exports this file: node.cjs is built from node.js.
|
|
3
|
+
import type {
|
|
4
|
+
FxAgent,
|
|
5
|
+
FxAgentOptions,
|
|
6
|
+
FxBackendInfo,
|
|
7
|
+
FxBackendInfoOptions,
|
|
8
|
+
FxEngine,
|
|
9
|
+
FxEngineOptions,
|
|
10
|
+
FxNodeBackendOptions,
|
|
11
|
+
FxTerminal,
|
|
12
|
+
FxTerminalOptions,
|
|
13
|
+
} from "./libfx.cjs";
|
|
14
|
+
|
|
15
|
+
export {
|
|
16
|
+
createMemoryPersistence,
|
|
17
|
+
encodeXtermKeyEvent,
|
|
18
|
+
FxFencedError,
|
|
19
|
+
FxJournalVersionError,
|
|
20
|
+
fxSdkApiVersion,
|
|
21
|
+
listModels,
|
|
22
|
+
memory,
|
|
23
|
+
supportsJspi,
|
|
24
|
+
wakeHandler,
|
|
25
|
+
xtermAdapter,
|
|
26
|
+
} from "./libfx.cjs";
|
|
27
|
+
|
|
28
|
+
export type {
|
|
29
|
+
Durability,
|
|
30
|
+
FxAccepted,
|
|
31
|
+
FxAgent,
|
|
32
|
+
FxAgentEvent,
|
|
33
|
+
FxAgentHostTool,
|
|
34
|
+
FxAgentKeyedTool,
|
|
35
|
+
FxAgentOptions,
|
|
36
|
+
FxAgentTool,
|
|
37
|
+
FxAgentTools,
|
|
38
|
+
FxApiKeyCredentials,
|
|
39
|
+
FxBackendAttempt,
|
|
40
|
+
FxBackendChoice,
|
|
41
|
+
FxBackendInfo,
|
|
42
|
+
FxBackendInfoOptions,
|
|
43
|
+
FxBackendReason,
|
|
44
|
+
FxBackendReasonCode,
|
|
45
|
+
FxBytes,
|
|
46
|
+
FxCheckpointMeta,
|
|
47
|
+
FxCodexProvider,
|
|
48
|
+
FxCustomProvider,
|
|
49
|
+
FxCustomProviderDefinition,
|
|
50
|
+
FxCustomProviderModel,
|
|
51
|
+
FxEffort,
|
|
52
|
+
FxEngine,
|
|
53
|
+
FxEngineEvent,
|
|
54
|
+
FxEngineOptions,
|
|
55
|
+
FxEnginePromptOptions,
|
|
56
|
+
FxEngineStorage,
|
|
57
|
+
FxEngineTurn,
|
|
58
|
+
FxEngineTurnResult,
|
|
59
|
+
FxErrorSummary,
|
|
60
|
+
FxFetch,
|
|
61
|
+
FxFollowUp,
|
|
62
|
+
FxGatewayProvider,
|
|
63
|
+
FxGrokProvider,
|
|
64
|
+
FxHostTool,
|
|
65
|
+
FxHooks,
|
|
66
|
+
FxHookEvent,
|
|
67
|
+
FxHookMessage,
|
|
68
|
+
FxHookToolCall,
|
|
69
|
+
FxIdleResult,
|
|
70
|
+
FxImageBlock,
|
|
71
|
+
FxJsonSchema,
|
|
72
|
+
FxKeyedTool,
|
|
73
|
+
FxKeyEventLike,
|
|
74
|
+
FxListModelsOptions,
|
|
75
|
+
FxModelCatalogEntry,
|
|
76
|
+
FxModelChoice,
|
|
77
|
+
FxModelOptions,
|
|
78
|
+
FxNodeBackendOptions,
|
|
79
|
+
FxNodeWasmSource,
|
|
80
|
+
FxOnAmbiguous,
|
|
81
|
+
FxPromptBlock,
|
|
82
|
+
FxPromptInput,
|
|
83
|
+
FxPromptOptions,
|
|
84
|
+
FxProviderCredentials,
|
|
85
|
+
FxProviderTool,
|
|
86
|
+
FxResizedImage,
|
|
87
|
+
FxResourceBlock,
|
|
88
|
+
FxResumeOptions,
|
|
89
|
+
FxResumeTurn,
|
|
90
|
+
FxSession,
|
|
91
|
+
FxSessionEvent,
|
|
92
|
+
FxSessionImageBlock,
|
|
93
|
+
FxSessionOptions,
|
|
94
|
+
FxSessionPromptInput,
|
|
95
|
+
FxSessionTurnEvent,
|
|
96
|
+
FxSharedOptions,
|
|
97
|
+
FxSteer,
|
|
98
|
+
FxSteerOptions,
|
|
99
|
+
FxSteered,
|
|
100
|
+
FxSteeringInput,
|
|
101
|
+
FxStopReason,
|
|
102
|
+
FxStreamLine,
|
|
103
|
+
FxTerminal,
|
|
104
|
+
FxTerminalAdapter,
|
|
105
|
+
FxTerminalEvent,
|
|
106
|
+
FxTerminalOptions,
|
|
107
|
+
FxTextBlock,
|
|
108
|
+
FxTool,
|
|
109
|
+
FxToolContext,
|
|
110
|
+
FxToolObservation,
|
|
111
|
+
FxWaitRequest,
|
|
112
|
+
FxWaitResponse,
|
|
113
|
+
FxToolImage,
|
|
114
|
+
FxToolResult,
|
|
115
|
+
FxTools,
|
|
116
|
+
FxTurn,
|
|
117
|
+
FxTurnEvent,
|
|
118
|
+
FxTurnResult,
|
|
119
|
+
FxTurnView,
|
|
120
|
+
FxUsage,
|
|
121
|
+
FxWasmModule,
|
|
122
|
+
FxWorkspace,
|
|
123
|
+
FxWorkspaceExecResult,
|
|
124
|
+
FxXtermLike,
|
|
125
|
+
JournalRecord,
|
|
126
|
+
JsonObject,
|
|
127
|
+
JsonValue,
|
|
128
|
+
MemoryOptions,
|
|
129
|
+
MemoryPersistence,
|
|
130
|
+
Persistence,
|
|
131
|
+
PersistenceLoadResult,
|
|
132
|
+
} from "./libfx.cjs";
|
|
133
|
+
|
|
134
|
+
/** Options for `createFxAgent()` on Node.js. */
|
|
135
|
+
export type FxNodeAgentOptions = FxAgentOptions & FxNodeBackendOptions;
|
|
136
|
+
|
|
137
|
+
/** Options for `createFxEngine()` on Node.js. */
|
|
138
|
+
export type FxNodeEngineOptions = FxEngineOptions & FxNodeBackendOptions;
|
|
139
|
+
|
|
140
|
+
/** Options for `createFxTerminal()` on Node.js. */
|
|
141
|
+
export type FxNodeTerminalOptions = FxTerminalOptions & FxNodeBackendOptions;
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* An agent whose sessions survive crashes, timeouts, and redeployments. It
|
|
145
|
+
* returns at once and does no I/O until a session runs a turn. Without
|
|
146
|
+
* `durability`, sessions live in Vercel's World on Vercel and in local files
|
|
147
|
+
* elsewhere.
|
|
148
|
+
*/
|
|
149
|
+
export declare function createFxAgent(options?: FxNodeAgentOptions): FxAgent;
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* The kernel under `createFxAgent()`: one conversation, held in the memory of
|
|
153
|
+
* the process that runs it. `apiKey` is required, and it resolves once its
|
|
154
|
+
* backend has loaded.
|
|
155
|
+
*/
|
|
156
|
+
export declare function createFxEngine(options: FxNodeEngineOptions): Promise<FxEngine>;
|
|
157
|
+
|
|
158
|
+
/** The interactive terminal harness. */
|
|
159
|
+
export declare function createFxTerminal(options: FxNodeTerminalOptions): Promise<FxTerminal>;
|
|
160
|
+
|
|
161
|
+
/** Inspects backend availability without creating an agent or terminal. */
|
|
162
|
+
export declare function getBackendInfo(options?: FxBackendInfoOptions): Promise<FxBackendInfo>;
|
|
163
|
+
|
|
164
|
+
/** The version of the libfx agent API. */
|
|
165
|
+
export declare const libfxApiVersion: 3;
|
package/types/node.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// `libfx/skills/node` (skills-node.js): loads a `SKILL.md` explicitly in
|
|
2
|
+
// Node.js or Bun.
|
|
3
|
+
import type { FxAgentTool } from "./libfx.cjs";
|
|
4
|
+
import type { SkillRecord, SkillResource } from "./skills.js";
|
|
5
|
+
|
|
6
|
+
export { createSkillsAdapter } from "./skills.js";
|
|
7
|
+
export type { SkillRecord, SkillResource, SkillsAdapter } from "./skills.js";
|
|
8
|
+
|
|
9
|
+
/** Options for `loadSkillFile()`. */
|
|
10
|
+
export interface LoadSkillFileOptions {
|
|
11
|
+
/** Replaces `fs.promises.readFile`. */
|
|
12
|
+
readFile?: (path: string, encoding: "utf8") => string | Promise<string>;
|
|
13
|
+
resources?: readonly SkillResource[];
|
|
14
|
+
tools?: readonly FxAgentTool[];
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** A skill read from a `SKILL.md`: its frontmatter `name` and `description`, and its body as instructions. */
|
|
18
|
+
export interface LoadedSkill extends SkillRecord {
|
|
19
|
+
description: string;
|
|
20
|
+
resources: readonly SkillResource[];
|
|
21
|
+
tools: readonly FxAgentTool[];
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** Reads one `SKILL.md`. Without a frontmatter `name`, the file name is the skill's name. */
|
|
25
|
+
export declare function loadSkillFile(path: string, options?: LoadSkillFileOptions): Promise<LoadedSkill>;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// `libfx/skills` (skills.js): instructions and tools from already-loaded
|
|
2
|
+
// skill records.
|
|
3
|
+
import type { FxAgentTool } from "./libfx.cjs";
|
|
4
|
+
|
|
5
|
+
/** A resource whose text joins its skill's instructions. */
|
|
6
|
+
export interface SkillResource {
|
|
7
|
+
uri: string;
|
|
8
|
+
text: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/** An already-loaded skill. */
|
|
12
|
+
export interface SkillRecord {
|
|
13
|
+
name: string;
|
|
14
|
+
instructions: string;
|
|
15
|
+
description?: string;
|
|
16
|
+
resources?: readonly SkillResource[];
|
|
17
|
+
/** Each host tool sets `idempotent`, as `createFxAgent()` requires. */
|
|
18
|
+
tools?: readonly FxAgentTool[];
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** What `createSkillsAdapter()` returns: spread it into the agent options. */
|
|
22
|
+
export interface SkillsAdapter {
|
|
23
|
+
instructions: string;
|
|
24
|
+
tools: FxAgentTool[];
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** Turns up to 64 skill records into instructions and tools. */
|
|
28
|
+
export declare function createSkillsAdapter(records: readonly SkillRecord[]): SkillsAdapter;
|
package/types/wasm.d.ts
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
// `libfx/wasm` (fx-sdk.js): the WebAssembly SDK with no packaged asset paths,
|
|
2
|
+
// so every factory takes its `wasm` explicitly.
|
|
3
|
+
import type { FxEngine, FxEngineOptions, FxTerminal, FxTerminalOptions, FxWasmSource } from "./libfx.cjs";
|
|
4
|
+
|
|
5
|
+
export {
|
|
6
|
+
createMemoryPersistence,
|
|
7
|
+
encodeXtermKeyEvent,
|
|
8
|
+
FxFencedError,
|
|
9
|
+
FxJournalVersionError,
|
|
10
|
+
fxSdkApiVersion,
|
|
11
|
+
listModels,
|
|
12
|
+
supportsJspi,
|
|
13
|
+
xtermAdapter,
|
|
14
|
+
} from "./libfx.cjs";
|
|
15
|
+
|
|
16
|
+
export type {
|
|
17
|
+
FxApiKeyCredentials,
|
|
18
|
+
FxBytes,
|
|
19
|
+
FxCheckpointMeta,
|
|
20
|
+
FxCodexProvider,
|
|
21
|
+
FxCustomProvider,
|
|
22
|
+
FxCustomProviderDefinition,
|
|
23
|
+
FxCustomProviderModel,
|
|
24
|
+
FxEffort,
|
|
25
|
+
FxEngine,
|
|
26
|
+
FxEngineEvent,
|
|
27
|
+
FxEngineOptions,
|
|
28
|
+
FxEnginePromptOptions,
|
|
29
|
+
FxEngineStorage,
|
|
30
|
+
FxEngineTurn,
|
|
31
|
+
FxEngineTurnResult,
|
|
32
|
+
FxErrorSummary,
|
|
33
|
+
FxFetch,
|
|
34
|
+
FxFollowUp,
|
|
35
|
+
FxGatewayProvider,
|
|
36
|
+
FxGrokProvider,
|
|
37
|
+
FxHostTool,
|
|
38
|
+
FxHooks,
|
|
39
|
+
FxHookEvent,
|
|
40
|
+
FxHookMessage,
|
|
41
|
+
FxHookToolCall,
|
|
42
|
+
FxImageBlock,
|
|
43
|
+
FxJsonSchema,
|
|
44
|
+
FxKeyedTool,
|
|
45
|
+
FxKeyEventLike,
|
|
46
|
+
FxListModelsOptions,
|
|
47
|
+
FxModelCatalogEntry,
|
|
48
|
+
FxModelChoice,
|
|
49
|
+
FxModelOptions,
|
|
50
|
+
FxOnAmbiguous,
|
|
51
|
+
FxPromptBlock,
|
|
52
|
+
FxPromptInput,
|
|
53
|
+
FxProviderCredentials,
|
|
54
|
+
FxProviderTool,
|
|
55
|
+
FxResizedImage,
|
|
56
|
+
FxResourceBlock,
|
|
57
|
+
FxResumeOptions,
|
|
58
|
+
FxSharedOptions,
|
|
59
|
+
FxSteer,
|
|
60
|
+
FxSteeringInput,
|
|
61
|
+
FxStopReason,
|
|
62
|
+
FxTerminal,
|
|
63
|
+
FxTerminalAdapter,
|
|
64
|
+
FxTerminalEvent,
|
|
65
|
+
FxTerminalOptions,
|
|
66
|
+
FxTextBlock,
|
|
67
|
+
FxTool,
|
|
68
|
+
FxToolContext,
|
|
69
|
+
FxToolObservation,
|
|
70
|
+
FxWaitRequest,
|
|
71
|
+
FxWaitResponse,
|
|
72
|
+
FxToolImage,
|
|
73
|
+
FxToolResult,
|
|
74
|
+
FxTools,
|
|
75
|
+
FxTurnEvent,
|
|
76
|
+
FxUsage,
|
|
77
|
+
FxWasmModule,
|
|
78
|
+
FxWasmSource,
|
|
79
|
+
FxWorkspace,
|
|
80
|
+
FxWorkspaceExecResult,
|
|
81
|
+
FxXtermLike,
|
|
82
|
+
JournalRecord,
|
|
83
|
+
JsonObject,
|
|
84
|
+
JsonValue,
|
|
85
|
+
MemoryPersistence,
|
|
86
|
+
Persistence,
|
|
87
|
+
PersistenceLoadResult,
|
|
88
|
+
} from "./libfx.cjs";
|
|
89
|
+
|
|
90
|
+
/** Options for `createFxEngine()` from `libfx/wasm`. */
|
|
91
|
+
export type FxWasmEngineOptions = FxEngineOptions & {
|
|
92
|
+
/** The `fx-core.wasm` asset. */
|
|
93
|
+
wasm: FxWasmSource;
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
/** Options for `createFxTerminal()` from `libfx/wasm`. */
|
|
97
|
+
export type FxWasmTerminalOptions = FxTerminalOptions & {
|
|
98
|
+
/** The `fx-term.wasm` asset. */
|
|
99
|
+
wasm: FxWasmSource;
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
/** One session on one fx core, with no durability of its own. Requires JSPI. */
|
|
103
|
+
export declare function createFxEngine(options: FxWasmEngineOptions): Promise<FxEngine>;
|
|
104
|
+
|
|
105
|
+
/** The interactive terminal harness on WebAssembly. Requires JSPI. */
|
|
106
|
+
export declare function createFxTerminal(options: FxWasmTerminalOptions): Promise<FxTerminal>;
|