@outlit/pi 3.0.0 → 4.0.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 +8 -2
- package/dist/extension.cjs +138 -4
- package/dist/extension.cjs.map +1 -1
- package/dist/extension.js +139 -4
- package/dist/extension.js.map +1 -1
- package/dist/index.cjs +142 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +29 -2
- package/dist/index.d.ts +29 -2
- package/dist/index.js +141 -4
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/skills/outlit/SKILL.md +4 -3
package/README.md
CHANGED
|
@@ -19,7 +19,7 @@ pi
|
|
|
19
19
|
|
|
20
20
|
## Tools
|
|
21
21
|
|
|
22
|
-
The default extension registers the default customer intelligence tools from `@outlit/tools
|
|
22
|
+
The default extension registers the default customer intelligence tools from `@outlit/tools`, plus the two read-only toolset tools (`piDefaultToolNames`):
|
|
23
23
|
|
|
24
24
|
- `outlit_list_customers`
|
|
25
25
|
- `outlit_list_customer_fields`
|
|
@@ -31,8 +31,12 @@ The default extension registers the default customer intelligence tools from `@o
|
|
|
31
31
|
- `outlit_get_source`
|
|
32
32
|
- `outlit_list_sources`
|
|
33
33
|
- `outlit_search_customer_context`
|
|
34
|
+
- `outlit_list_toolsets`
|
|
35
|
+
- `outlit_load_toolset`
|
|
34
36
|
|
|
35
|
-
|
|
37
|
+
Pi registers its tools when a session starts, so `outlit_list_toolsets` and `outlit_load_toolset` tell the agent which toolset holds a tool it lacks; enabling that toolset is the extension's `toolsets` option (below).
|
|
38
|
+
|
|
39
|
+
SQL and the other Pi-supported Platform capabilities are available from `@outlit/tools`, but the default Pi policy intentionally stays focused on customer intelligence. A custom Pi extension can opt into every Pi-supported tool with `piToolNames`, including task reads and actions, customer ownership and access actions, product-facing Feature list, create and archive tools, plus safe integration setup, destination, activation, workspace-settings actions, and `outlit_submit_feedback` product feedback intake. The analytical policy (`analyticalToolNames`) is unchanged and does not include the toolset tools.
|
|
36
40
|
|
|
37
41
|
For analytical agents that need cohorts, usage trends, revenue filters, activation gaps, or aggregate checks, import `analyticalToolNames`. It combines the default customer intelligence tools with `outlit_get_schema` and `outlit_query` without exposing every customer tool:
|
|
38
42
|
|
|
@@ -68,6 +72,8 @@ export default createOutlitPiExtension({
|
|
|
68
72
|
})
|
|
69
73
|
```
|
|
70
74
|
|
|
75
|
+
A call that fails (a gateway error, a rate limit, a dropped connection) is returned as the tool result `{ "error": { code, message, retryable, requestId, next, missingPermission, validationIssues, retryAfterSeconds } }`, with the fields the gateway sent, so the agent can fix its input, wait or report the missing permission. `details.error` holds the same object. A missing API key or non-object input still throws.
|
|
76
|
+
|
|
71
77
|
A tool result that comes with a deprecation or an input notice from Outlit (for example a limit lowered to the maximum) carries it as a second text block after the JSON.
|
|
72
78
|
|
|
73
79
|
To register every Pi-supported tool:
|
package/dist/extension.cjs
CHANGED
|
@@ -26,10 +26,103 @@ module.exports = __toCommonJS(extension_exports);
|
|
|
26
26
|
|
|
27
27
|
// src/index.ts
|
|
28
28
|
var import_tools = require("@outlit/tools");
|
|
29
|
+
|
|
30
|
+
// package.json
|
|
31
|
+
var package_default = {
|
|
32
|
+
name: "@outlit/pi",
|
|
33
|
+
version: "4.0.0",
|
|
34
|
+
description: "Pi package for Outlit customer intelligence tools and skill guidance",
|
|
35
|
+
license: "Apache-2.0",
|
|
36
|
+
author: "Outlit AI",
|
|
37
|
+
repository: {
|
|
38
|
+
type: "git",
|
|
39
|
+
url: "https://github.com/OutlitAI/outlit-sdk.git",
|
|
40
|
+
directory: "packages/pi"
|
|
41
|
+
},
|
|
42
|
+
bugs: {
|
|
43
|
+
url: "https://github.com/OutlitAI/outlit-sdk/issues"
|
|
44
|
+
},
|
|
45
|
+
homepage: "https://docs.outlit.ai/ai-integrations/pi",
|
|
46
|
+
keywords: [
|
|
47
|
+
"outlit",
|
|
48
|
+
"pi",
|
|
49
|
+
"pi-package",
|
|
50
|
+
"agents",
|
|
51
|
+
"ai-agents",
|
|
52
|
+
"mcp",
|
|
53
|
+
"customer-intelligence"
|
|
54
|
+
],
|
|
55
|
+
pi: {
|
|
56
|
+
extensions: [
|
|
57
|
+
"./dist/extension.js"
|
|
58
|
+
],
|
|
59
|
+
skills: [
|
|
60
|
+
"./skills"
|
|
61
|
+
]
|
|
62
|
+
},
|
|
63
|
+
publishConfig: {
|
|
64
|
+
access: "public"
|
|
65
|
+
},
|
|
66
|
+
type: "module",
|
|
67
|
+
main: "./dist/index.cjs",
|
|
68
|
+
module: "./dist/index.js",
|
|
69
|
+
types: "./dist/index.d.ts",
|
|
70
|
+
exports: {
|
|
71
|
+
".": {
|
|
72
|
+
types: "./dist/index.d.ts",
|
|
73
|
+
import: "./dist/index.js",
|
|
74
|
+
require: "./dist/index.cjs",
|
|
75
|
+
default: "./dist/index.js"
|
|
76
|
+
},
|
|
77
|
+
"./extension": {
|
|
78
|
+
types: "./dist/extension.d.ts",
|
|
79
|
+
import: "./dist/extension.js",
|
|
80
|
+
require: "./dist/extension.cjs",
|
|
81
|
+
default: "./dist/extension.js"
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
files: [
|
|
85
|
+
"dist",
|
|
86
|
+
"skills",
|
|
87
|
+
"README.md"
|
|
88
|
+
],
|
|
89
|
+
scripts: {
|
|
90
|
+
build: "tsup",
|
|
91
|
+
dev: "tsup --watch",
|
|
92
|
+
clean: "rm -rf dist .turbo node_modules",
|
|
93
|
+
lint: "biome check . --write",
|
|
94
|
+
format: "biome format --write .",
|
|
95
|
+
typecheck: "tsc --noEmit",
|
|
96
|
+
test: "vitest run"
|
|
97
|
+
},
|
|
98
|
+
dependencies: {
|
|
99
|
+
"@outlit/tools": "^4.0.0"
|
|
100
|
+
},
|
|
101
|
+
peerDependencies: {
|
|
102
|
+
"@mariozechner/pi-coding-agent": "*",
|
|
103
|
+
"@sinclair/typebox": "*"
|
|
104
|
+
},
|
|
105
|
+
devDependencies: {
|
|
106
|
+
"@mariozechner/pi-coding-agent": "^0.67.1",
|
|
107
|
+
"@outlit/typescript-config": "workspace:*",
|
|
108
|
+
"@sinclair/typebox": "^0.34.41",
|
|
109
|
+
tsup: "^8.5.1",
|
|
110
|
+
typescript: "^5.9.3",
|
|
111
|
+
vitest: "^4.0.18"
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
// src/index.ts
|
|
29
116
|
var import_tools2 = require("@outlit/tools");
|
|
30
117
|
var OUTLIT_API_KEY_ENV = "OUTLIT_API_KEY";
|
|
31
118
|
var OUTLIT_API_URL_ENV = "OUTLIT_API_URL";
|
|
119
|
+
var OUTLIT_PI_CLIENT = `@outlit/pi/${package_default.version}`;
|
|
32
120
|
var piToolNameSet = new Set(import_tools.piToolNames);
|
|
121
|
+
var piDefaultToolNames = [
|
|
122
|
+
...import_tools.defaultToolNames,
|
|
123
|
+
"outlit_list_toolsets",
|
|
124
|
+
"outlit_load_toolset"
|
|
125
|
+
];
|
|
33
126
|
function createOutlitPiExtension(options = {}) {
|
|
34
127
|
return function outlitPiExtension(pi) {
|
|
35
128
|
for (const tool of createOutlitPiTools(options)) {
|
|
@@ -61,12 +154,23 @@ function createOutlitPiTool(toolName, options = {}) {
|
|
|
61
154
|
apiKey: resolveApiKey(options),
|
|
62
155
|
baseUrl: resolveBaseUrl(options),
|
|
63
156
|
fetch: options.fetch,
|
|
157
|
+
client: OUTLIT_PI_CLIENT,
|
|
64
158
|
onResponse: (info) => {
|
|
65
159
|
responseInfo = info;
|
|
66
160
|
}
|
|
67
161
|
});
|
|
68
|
-
const
|
|
69
|
-
|
|
162
|
+
const input = normalizeToolInput(params);
|
|
163
|
+
try {
|
|
164
|
+
const result = await client.callTool(toolName, input);
|
|
165
|
+
return formatToolResult(toolName, result, responseInfo);
|
|
166
|
+
} catch (error) {
|
|
167
|
+
return formatToolError(
|
|
168
|
+
toolName,
|
|
169
|
+
toToolError(error, responseInfo),
|
|
170
|
+
responseNotices(responseInfo),
|
|
171
|
+
responseInfo
|
|
172
|
+
);
|
|
173
|
+
}
|
|
70
174
|
}
|
|
71
175
|
};
|
|
72
176
|
}
|
|
@@ -82,7 +186,7 @@ function formatOutlitToolLabel(toolName) {
|
|
|
82
186
|
}
|
|
83
187
|
function resolveToolNames(options) {
|
|
84
188
|
const names = [
|
|
85
|
-
...options.toolNames ?? (options.toolsets ? [] :
|
|
189
|
+
...options.toolNames ?? (options.toolsets ? [] : piDefaultToolNames),
|
|
86
190
|
...options.toolsets ? (0, import_tools.toolNamesInToolsets)(options.toolsets) : []
|
|
87
191
|
];
|
|
88
192
|
return [...new Set(names)].map((name) => {
|
|
@@ -122,6 +226,35 @@ function responseNotices(info) {
|
|
|
122
226
|
...info.notices
|
|
123
227
|
];
|
|
124
228
|
}
|
|
229
|
+
function toToolError(error, info) {
|
|
230
|
+
if ((0, import_tools.isOutlitToolsApiError)(error)) {
|
|
231
|
+
if (error.envelope) return { ...error.envelope, status: error.status };
|
|
232
|
+
return {
|
|
233
|
+
message: error.message,
|
|
234
|
+
retryable: error.status === 429 || error.status >= 500,
|
|
235
|
+
status: error.status,
|
|
236
|
+
...error.requestId ?? info?.requestId ? { requestId: error.requestId ?? info?.requestId } : {}
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
return { message: error instanceof Error ? error.message : String(error), retryable: true };
|
|
240
|
+
}
|
|
241
|
+
function formatToolError(toolName, error, notices, info) {
|
|
242
|
+
const result = { error };
|
|
243
|
+
return {
|
|
244
|
+
content: [
|
|
245
|
+
{ type: "text", text: JSON.stringify(result, null, 2) },
|
|
246
|
+
...notices.length > 0 ? [{ type: "text", text: `Notice: ${notices.join(" ")}` }] : []
|
|
247
|
+
],
|
|
248
|
+
details: { toolName, result, error, ...responseIds(info, error.requestId) }
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
function responseIds(info, fallbackRequestId) {
|
|
252
|
+
const requestId = info?.requestId ?? fallbackRequestId;
|
|
253
|
+
return {
|
|
254
|
+
...requestId ? { requestId } : {},
|
|
255
|
+
...info?.version ? { version: info.version } : {}
|
|
256
|
+
};
|
|
257
|
+
}
|
|
125
258
|
function formatToolResult(toolName, result, info) {
|
|
126
259
|
const notices = responseNotices(info);
|
|
127
260
|
return {
|
|
@@ -132,7 +265,8 @@ function formatToolResult(toolName, result, info) {
|
|
|
132
265
|
],
|
|
133
266
|
details: {
|
|
134
267
|
toolName,
|
|
135
|
-
result
|
|
268
|
+
result,
|
|
269
|
+
...responseIds(info)
|
|
136
270
|
}
|
|
137
271
|
};
|
|
138
272
|
}
|
package/dist/extension.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/extension.ts","../src/index.ts"],"sourcesContent":["import { createOutlitPiExtension } from \"./index.js\"\n\nexport default createOutlitPiExtension()\n","import type { AgentToolResult, ExtensionAPI, ToolDefinition } from \"@mariozechner/pi-coding-agent\"\nimport {\n createOutlitClient,\n DEFAULT_OUTLIT_API_URL,\n defaultToolNames,\n getPublicToolContract,\n isPublicToolName,\n type OutlitToolsFetch,\n type OutlitToolsResponseInfo,\n type PiToolName,\n piToolNames,\n type ToolsetName,\n toolNamesInToolsets,\n} from \"@outlit/tools\"\nimport type { TSchema } from \"@sinclair/typebox\"\n\nexport const OUTLIT_API_KEY_ENV = \"OUTLIT_API_KEY\"\nexport const OUTLIT_API_URL_ENV = \"OUTLIT_API_URL\"\n\nconst piToolNameSet = new Set<string>(piToolNames)\n\nexport type OutlitPiExtensionOptions = {\n apiKey?: string\n baseUrl?: string\n fetch?: OutlitToolsFetch\n toolNames?: readonly PiToolName[]\n /**\n * Register every tool in these Core toolsets (core, work, identity, admin, meta). With `toolNames`\n * too, both apply; with neither, the default read-only tools are registered.\n */\n toolsets?: readonly ToolsetName[]\n}\n\nexport type OutlitPiRegistry = Pick<ExtensionAPI, \"registerTool\">\n\nexport type OutlitPiToolDetails = {\n toolName: PiToolName\n result: unknown\n}\n\nexport type OutlitPiToolDefinition = ToolDefinition<TSchema, OutlitPiToolDetails>\n\nexport function createOutlitPiExtension(options: OutlitPiExtensionOptions = {}) {\n return function outlitPiExtension(pi: OutlitPiRegistry) {\n for (const tool of createOutlitPiTools(options)) {\n pi.registerTool(tool)\n }\n }\n}\n\nexport function createOutlitPiTools(\n options: OutlitPiExtensionOptions = {},\n): OutlitPiToolDefinition[] {\n return resolveToolNames(options).map((toolName) => createOutlitPiTool(toolName, options))\n}\n\nexport function createOutlitPiTool(\n toolName: PiToolName,\n options: OutlitPiExtensionOptions = {},\n): OutlitPiToolDefinition {\n if (!isPublicToolName(toolName)) {\n throw new Error(`Unknown Outlit public tool: ${toolName}`)\n }\n if (!piToolNameSet.has(toolName)) {\n throw new Error(`Tool is not available in @outlit/pi: ${toolName}`)\n }\n\n const contract = getPublicToolContract(toolName)\n const label = formatOutlitToolLabel(toolName)\n\n return {\n name: toolName,\n label,\n description: contract.description,\n promptSnippet: `${label}: ${firstLine(contract.description)}`,\n parameters: toPiToolParameters(contract.inputSchema),\n async execute(_toolCallId, params) {\n let responseInfo: OutlitToolsResponseInfo | undefined\n const client = createOutlitClient({\n apiKey: resolveApiKey(options),\n baseUrl: resolveBaseUrl(options),\n fetch: options.fetch,\n onResponse: (info) => {\n responseInfo = info\n },\n })\n const result = await client.callTool(toolName, normalizeToolInput(params))\n\n return formatToolResult(toolName, result, responseInfo)\n },\n }\n}\n\nfunction toPiToolParameters(inputSchema: unknown): TSchema {\n if (inputSchema === null || typeof inputSchema !== \"object\" || Array.isArray(inputSchema)) {\n return inputSchema as TSchema\n }\n\n const { $schema: _schema, ...schema } = inputSchema as Record<string, unknown>\n return schema as unknown as TSchema\n}\n\nexport function formatOutlitToolLabel(toolName: PiToolName): string {\n return toolName\n .split(\"_\")\n .map((part) => part.charAt(0).toUpperCase() + part.slice(1))\n .join(\" \")\n}\n\nfunction resolveToolNames(options: OutlitPiExtensionOptions): PiToolName[] {\n const names: readonly string[] = [\n ...(options.toolNames ?? (options.toolsets ? [] : defaultToolNames)),\n ...(options.toolsets ? toolNamesInToolsets(options.toolsets) : []),\n ]\n\n return [...new Set(names)].map((name) => {\n if (!isPublicToolName(name)) {\n throw new Error(`Unknown Outlit public tool: ${name}`)\n }\n\n return name as PiToolName\n })\n}\n\nfunction resolveApiKey(options: OutlitPiExtensionOptions): string {\n const apiKey = normalizeString(options.apiKey) ?? normalizeString(process.env[OUTLIT_API_KEY_ENV])\n\n if (!apiKey) {\n throw new Error(`${OUTLIT_API_KEY_ENV} is required to use @outlit/pi tools`)\n }\n\n return apiKey\n}\n\nfunction resolveBaseUrl(options: OutlitPiExtensionOptions): string {\n return (\n normalizeString(options.baseUrl) ??\n normalizeString(process.env[OUTLIT_API_URL_ENV]) ??\n DEFAULT_OUTLIT_API_URL\n )\n}\n\nfunction normalizeString(value: string | undefined): string | undefined {\n const trimmed = value?.trim()\n return trimmed ? trimmed : undefined\n}\n\nfunction normalizeToolInput(params: unknown): Record<string, unknown> {\n if (params === undefined) {\n return {}\n }\n\n if (params === null || typeof params !== \"object\" || Array.isArray(params)) {\n throw new TypeError(\"Outlit Pi tool input must be an object\")\n }\n\n return params as Record<string, unknown>\n}\n\n/** What the gateway said beside the result, as sentences for the agent: a deprecation, then notices. */\nfunction responseNotices(info: OutlitToolsResponseInfo | undefined): string[] {\n if (!info) return []\n return [\n ...(info.deprecation ? [`${info.deprecation.message} (until ${info.deprecation.until})`] : []),\n ...info.notices,\n ]\n}\n\nfunction formatToolResult(\n toolName: PiToolName,\n result: unknown,\n info?: OutlitToolsResponseInfo,\n): AgentToolResult<OutlitPiToolDetails> {\n const notices = responseNotices(info)\n return {\n content: [\n { type: \"text\", text: JSON.stringify(result, null, 2) ?? String(result) },\n // After the result, so a reader of the first block still gets the JSON alone.\n ...(notices.length > 0\n ? [{ type: \"text\" as const, text: `Notice: ${notices.join(\" \")}` }]\n : []),\n ],\n details: {\n toolName,\n result,\n },\n }\n}\n\nfunction firstLine(value: string): string {\n return value.split(\"\\n\", 1)[0] ?? value\n}\n\nexport type { PiToolName } from \"@outlit/tools\"\n/** @deprecated Use PiToolName. */\nexport type PublicToolName = PiToolName\nexport type { ToolsetName } from \"@outlit/tools\"\nexport {\n analyticalToolNames,\n defaultToolNames,\n piToolNames,\n piToolNames as allPublicToolNames,\n sqlToolNames,\n toolsetNames,\n} from \"@outlit/tools\"\n\nexport default createOutlitPiExtension()\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACCA,mBAYO;AAwLP,IAAAA,gBAOO;AA5LA,IAAM,qBAAqB;AAC3B,IAAM,qBAAqB;AAElC,IAAM,gBAAgB,IAAI,IAAY,wBAAW;AAuB1C,SAAS,wBAAwB,UAAoC,CAAC,GAAG;AAC9E,SAAO,SAAS,kBAAkB,IAAsB;AACtD,eAAW,QAAQ,oBAAoB,OAAO,GAAG;AAC/C,SAAG,aAAa,IAAI;AAAA,IACtB;AAAA,EACF;AACF;AAEO,SAAS,oBACd,UAAoC,CAAC,GACX;AAC1B,SAAO,iBAAiB,OAAO,EAAE,IAAI,CAAC,aAAa,mBAAmB,UAAU,OAAO,CAAC;AAC1F;AAEO,SAAS,mBACd,UACA,UAAoC,CAAC,GACb;AACxB,MAAI,KAAC,+BAAiB,QAAQ,GAAG;AAC/B,UAAM,IAAI,MAAM,+BAA+B,QAAQ,EAAE;AAAA,EAC3D;AACA,MAAI,CAAC,cAAc,IAAI,QAAQ,GAAG;AAChC,UAAM,IAAI,MAAM,wCAAwC,QAAQ,EAAE;AAAA,EACpE;AAEA,QAAM,eAAW,oCAAsB,QAAQ;AAC/C,QAAM,QAAQ,sBAAsB,QAAQ;AAE5C,SAAO;AAAA,IACL,MAAM;AAAA,IACN;AAAA,IACA,aAAa,SAAS;AAAA,IACtB,eAAe,GAAG,KAAK,KAAK,UAAU,SAAS,WAAW,CAAC;AAAA,IAC3D,YAAY,mBAAmB,SAAS,WAAW;AAAA,IACnD,MAAM,QAAQ,aAAa,QAAQ;AACjC,UAAI;AACJ,YAAM,aAAS,iCAAmB;AAA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/index.ts","../package.json"],"sourcesContent":["import { createOutlitPiExtension } from \"./index.js\"\n\nexport default createOutlitPiExtension()\n","import type { AgentToolResult, ExtensionAPI, ToolDefinition } from \"@mariozechner/pi-coding-agent\"\nimport {\n createOutlitClient,\n DEFAULT_OUTLIT_API_URL,\n defaultToolNames,\n getPublicToolContract,\n isOutlitToolsApiError,\n isPublicToolName,\n type OutlitToolsFetch,\n type OutlitToolsResponseInfo,\n type PiToolName,\n piToolNames,\n type ToolGatewayErrorEnvelope,\n type ToolsetName,\n toolNamesInToolsets,\n} from \"@outlit/tools\"\nimport type { TSchema } from \"@sinclair/typebox\"\nimport pkg from \"../package.json\" with { type: \"json\" }\n\nexport const OUTLIT_API_KEY_ENV = \"OUTLIT_API_KEY\"\nexport const OUTLIT_API_URL_ENV = \"OUTLIT_API_URL\"\n\n/** Sent as `x-outlit-client`, so Core can tell a Pi extension below a release's minimum version. */\nexport const OUTLIT_PI_CLIENT = `@outlit/pi/${pkg.version}`\n\nconst piToolNameSet = new Set<string>(piToolNames)\n\n/**\n * What the extension registers with no options: Core's default customer intelligence tools, plus the\n * two read-only toolset tools, so an agent that needs a tool outside this list can find out which\n * toolset holds it and tell the user to enable it (the `toolsets` option below). Pi registers tools\n * when the session starts, so loading a toolset never adds callable tools mid-session.\n */\nexport const piDefaultToolNames: readonly PiToolName[] = [\n ...defaultToolNames,\n \"outlit_list_toolsets\",\n \"outlit_load_toolset\",\n]\n\nexport type OutlitPiExtensionOptions = {\n apiKey?: string\n baseUrl?: string\n fetch?: OutlitToolsFetch\n toolNames?: readonly PiToolName[]\n /**\n * Register every tool in these Core toolsets (core, work, identity, admin, meta). With `toolNames`\n * too, both apply; with neither, the default read-only tools are registered.\n */\n toolsets?: readonly ToolsetName[]\n}\n\nexport type OutlitPiRegistry = Pick<ExtensionAPI, \"registerTool\">\n\n/**\n * What a failed call hands the agent: the gateway's whole error envelope (`code`, `message`,\n * `retryable`, `requestId`, and when present `next`, `missingPermission`, `validationIssues`,\n * `retryAfterSeconds`), plus the HTTP `status` when there was a response. A failure with no envelope\n * (a proxy's HTML error page, a dropped connection) carries a `message` and `retryable` only.\n */\nexport type OutlitPiToolError = Partial<ToolGatewayErrorEnvelope> & {\n message: string\n retryable: boolean\n status?: number\n}\n\nexport type OutlitPiToolDetails = {\n toolName: PiToolName\n /** The tool's result; `{ error }` when the call failed (see `error`). */\n result: unknown\n /** Set when the call failed at the gateway or the network; the agent sees it as the tool result. */\n error?: OutlitPiToolError\n /** Core's `outlit-request-id` for this call, success or failure: quote it when reporting a problem. */\n requestId?: string\n /** Core's `outlit-version`: the dated output version that answered. */\n version?: string\n}\n\nexport type OutlitPiToolDefinition = ToolDefinition<TSchema, OutlitPiToolDetails>\n\nexport function createOutlitPiExtension(options: OutlitPiExtensionOptions = {}) {\n return function outlitPiExtension(pi: OutlitPiRegistry) {\n for (const tool of createOutlitPiTools(options)) {\n pi.registerTool(tool)\n }\n }\n}\n\nexport function createOutlitPiTools(\n options: OutlitPiExtensionOptions = {},\n): OutlitPiToolDefinition[] {\n return resolveToolNames(options).map((toolName) => createOutlitPiTool(toolName, options))\n}\n\nexport function createOutlitPiTool(\n toolName: PiToolName,\n options: OutlitPiExtensionOptions = {},\n): OutlitPiToolDefinition {\n if (!isPublicToolName(toolName)) {\n throw new Error(`Unknown Outlit public tool: ${toolName}`)\n }\n if (!piToolNameSet.has(toolName)) {\n throw new Error(`Tool is not available in @outlit/pi: ${toolName}`)\n }\n\n const contract = getPublicToolContract(toolName)\n const label = formatOutlitToolLabel(toolName)\n\n return {\n name: toolName,\n label,\n description: contract.description,\n promptSnippet: `${label}: ${firstLine(contract.description)}`,\n parameters: toPiToolParameters(contract.inputSchema),\n async execute(_toolCallId, params) {\n let responseInfo: OutlitToolsResponseInfo | undefined\n const client = createOutlitClient({\n apiKey: resolveApiKey(options),\n baseUrl: resolveBaseUrl(options),\n fetch: options.fetch,\n client: OUTLIT_PI_CLIENT,\n onResponse: (info) => {\n responseInfo = info\n },\n })\n const input = normalizeToolInput(params)\n try {\n const result = await client.callTool(toolName, input)\n return formatToolResult(toolName, result, responseInfo)\n } catch (error) {\n // A failed call is something the agent can act on, not a crash: hand it the envelope.\n return formatToolError(\n toolName,\n toToolError(error, responseInfo),\n responseNotices(responseInfo),\n responseInfo,\n )\n }\n },\n }\n}\n\nfunction toPiToolParameters(inputSchema: unknown): TSchema {\n if (inputSchema === null || typeof inputSchema !== \"object\" || Array.isArray(inputSchema)) {\n return inputSchema as TSchema\n }\n\n const { $schema: _schema, ...schema } = inputSchema as Record<string, unknown>\n return schema as unknown as TSchema\n}\n\nexport function formatOutlitToolLabel(toolName: PiToolName): string {\n return toolName\n .split(\"_\")\n .map((part) => part.charAt(0).toUpperCase() + part.slice(1))\n .join(\" \")\n}\n\nfunction resolveToolNames(options: OutlitPiExtensionOptions): PiToolName[] {\n const names: readonly string[] = [\n ...(options.toolNames ?? (options.toolsets ? [] : piDefaultToolNames)),\n ...(options.toolsets ? toolNamesInToolsets(options.toolsets) : []),\n ]\n\n return [...new Set(names)].map((name) => {\n if (!isPublicToolName(name)) {\n throw new Error(`Unknown Outlit public tool: ${name}`)\n }\n\n return name as PiToolName\n })\n}\n\nfunction resolveApiKey(options: OutlitPiExtensionOptions): string {\n const apiKey = normalizeString(options.apiKey) ?? normalizeString(process.env[OUTLIT_API_KEY_ENV])\n\n if (!apiKey) {\n throw new Error(`${OUTLIT_API_KEY_ENV} is required to use @outlit/pi tools`)\n }\n\n return apiKey\n}\n\nfunction resolveBaseUrl(options: OutlitPiExtensionOptions): string {\n return (\n normalizeString(options.baseUrl) ??\n normalizeString(process.env[OUTLIT_API_URL_ENV]) ??\n DEFAULT_OUTLIT_API_URL\n )\n}\n\nfunction normalizeString(value: string | undefined): string | undefined {\n const trimmed = value?.trim()\n return trimmed ? trimmed : undefined\n}\n\nfunction normalizeToolInput(params: unknown): Record<string, unknown> {\n if (params === undefined) {\n return {}\n }\n\n if (params === null || typeof params !== \"object\" || Array.isArray(params)) {\n throw new TypeError(\"Outlit Pi tool input must be an object\")\n }\n\n return params as Record<string, unknown>\n}\n\n/** What the gateway said beside the result, as sentences for the agent: a deprecation, then notices. */\nfunction responseNotices(info: OutlitToolsResponseInfo | undefined): string[] {\n if (!info) return []\n return [\n ...(info.deprecation ? [`${info.deprecation.message} (until ${info.deprecation.until})`] : []),\n ...info.notices,\n ]\n}\n\nfunction toToolError(error: unknown, info?: OutlitToolsResponseInfo): OutlitPiToolError {\n if (isOutlitToolsApiError(error)) {\n if (error.envelope) return { ...error.envelope, status: error.status }\n return {\n message: error.message,\n retryable: error.status === 429 || error.status >= 500,\n status: error.status,\n ...((error.requestId ?? info?.requestId)\n ? { requestId: error.requestId ?? info?.requestId }\n : {}),\n }\n }\n // fetch rejecting (offline, DNS, reset) or a 200 whose body was not JSON.\n return { message: error instanceof Error ? error.message : String(error), retryable: true }\n}\n\nfunction formatToolError(\n toolName: PiToolName,\n error: OutlitPiToolError,\n notices: string[],\n info?: OutlitToolsResponseInfo,\n): AgentToolResult<OutlitPiToolDetails> {\n const result = { error }\n return {\n content: [\n { type: \"text\", text: JSON.stringify(result, null, 2) },\n ...(notices.length > 0\n ? [{ type: \"text\" as const, text: `Notice: ${notices.join(\" \")}` }]\n : []),\n ],\n details: { toolName, result, error, ...responseIds(info, error.requestId) },\n }\n}\n\nfunction responseIds(\n info: OutlitToolsResponseInfo | undefined,\n fallbackRequestId?: string,\n): { requestId?: string; version?: string } {\n const requestId = info?.requestId ?? fallbackRequestId\n return {\n ...(requestId ? { requestId } : {}),\n ...(info?.version ? { version: info.version } : {}),\n }\n}\n\nfunction formatToolResult(\n toolName: PiToolName,\n result: unknown,\n info?: OutlitToolsResponseInfo,\n): AgentToolResult<OutlitPiToolDetails> {\n const notices = responseNotices(info)\n return {\n content: [\n { type: \"text\", text: JSON.stringify(result, null, 2) ?? String(result) },\n // After the result, so a reader of the first block still gets the JSON alone.\n ...(notices.length > 0\n ? [{ type: \"text\" as const, text: `Notice: ${notices.join(\" \")}` }]\n : []),\n ],\n details: {\n toolName,\n result,\n ...responseIds(info),\n },\n }\n}\n\nfunction firstLine(value: string): string {\n return value.split(\"\\n\", 1)[0] ?? value\n}\n\nexport type { PiToolName } from \"@outlit/tools\"\n/** @deprecated Use PiToolName. */\nexport type PublicToolName = PiToolName\nexport type { ToolsetName } from \"@outlit/tools\"\nexport {\n analyticalToolNames,\n defaultToolNames,\n piToolNames,\n piToolNames as allPublicToolNames,\n sqlToolNames,\n toolsetNames,\n} from \"@outlit/tools\"\n\nexport default createOutlitPiExtension()\n","{\n \"name\": \"@outlit/pi\",\n \"version\": \"4.0.0\",\n \"description\": \"Pi package for Outlit customer intelligence tools and skill guidance\",\n \"license\": \"Apache-2.0\",\n \"author\": \"Outlit AI\",\n \"repository\": {\n \"type\": \"git\",\n \"url\": \"https://github.com/OutlitAI/outlit-sdk.git\",\n \"directory\": \"packages/pi\"\n },\n \"bugs\": {\n \"url\": \"https://github.com/OutlitAI/outlit-sdk/issues\"\n },\n \"homepage\": \"https://docs.outlit.ai/ai-integrations/pi\",\n \"keywords\": [\n \"outlit\",\n \"pi\",\n \"pi-package\",\n \"agents\",\n \"ai-agents\",\n \"mcp\",\n \"customer-intelligence\"\n ],\n \"pi\": {\n \"extensions\": [\n \"./dist/extension.js\"\n ],\n \"skills\": [\n \"./skills\"\n ]\n },\n \"publishConfig\": {\n \"access\": \"public\"\n },\n \"type\": \"module\",\n \"main\": \"./dist/index.cjs\",\n \"module\": \"./dist/index.js\",\n \"types\": \"./dist/index.d.ts\",\n \"exports\": {\n \".\": {\n \"types\": \"./dist/index.d.ts\",\n \"import\": \"./dist/index.js\",\n \"require\": \"./dist/index.cjs\",\n \"default\": \"./dist/index.js\"\n },\n \"./extension\": {\n \"types\": \"./dist/extension.d.ts\",\n \"import\": \"./dist/extension.js\",\n \"require\": \"./dist/extension.cjs\",\n \"default\": \"./dist/extension.js\"\n }\n },\n \"files\": [\n \"dist\",\n \"skills\",\n \"README.md\"\n ],\n \"scripts\": {\n \"build\": \"tsup\",\n \"dev\": \"tsup --watch\",\n \"clean\": \"rm -rf dist .turbo node_modules\",\n \"lint\": \"biome check . --write\",\n \"format\": \"biome format --write .\",\n \"typecheck\": \"tsc --noEmit\",\n \"test\": \"vitest run\"\n },\n \"dependencies\": {\n \"@outlit/tools\": \"^4.0.0\"\n },\n \"peerDependencies\": {\n \"@mariozechner/pi-coding-agent\": \"*\",\n \"@sinclair/typebox\": \"*\"\n },\n \"devDependencies\": {\n \"@mariozechner/pi-coding-agent\": \"^0.67.1\",\n \"@outlit/typescript-config\": \"workspace:*\",\n \"@sinclair/typebox\": \"^0.34.41\",\n \"tsup\": \"^8.5.1\",\n \"typescript\": \"^5.9.3\",\n \"vitest\": \"^4.0.18\"\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACCA,mBAcO;;;ACfP;AAAA,EACE,MAAQ;AAAA,EACR,SAAW;AAAA,EACX,aAAe;AAAA,EACf,SAAW;AAAA,EACX,QAAU;AAAA,EACV,YAAc;AAAA,IACZ,MAAQ;AAAA,IACR,KAAO;AAAA,IACP,WAAa;AAAA,EACf;AAAA,EACA,MAAQ;AAAA,IACN,KAAO;AAAA,EACT;AAAA,EACA,UAAY;AAAA,EACZ,UAAY;AAAA,IACV;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAAA,EACA,IAAM;AAAA,IACJ,YAAc;AAAA,MACZ;AAAA,IACF;AAAA,IACA,QAAU;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAAA,EACA,eAAiB;AAAA,IACf,QAAU;AAAA,EACZ;AAAA,EACA,MAAQ;AAAA,EACR,MAAQ;AAAA,EACR,QAAU;AAAA,EACV,OAAS;AAAA,EACT,SAAW;AAAA,IACT,KAAK;AAAA,MACH,OAAS;AAAA,MACT,QAAU;AAAA,MACV,SAAW;AAAA,MACX,SAAW;AAAA,IACb;AAAA,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AM,EAAE;AAAA;AAAA,MAExE,GAAI,QAAQ,SAAS,IACjB,CAAC,EAAE,MAAM,QAAiB,MAAM,WAAW,QAAQ,KAAK,GAAG,CAAC,GAAG,CAAC,IAChE,CAAC;AAAA,IACP;AAAA,IACA,SAAS;AAAA,MACP;AAAA,MACA;AAAA,MACA,GAAG,YAAY,IAAI;AAAA,IACrB;AAAA,EACF;AACF;AAEA,SAAS,UAAU,OAAuB;AACxC,SAAO,MAAM,MAAM,MAAM,CAAC,EAAE,CAAC,KAAK;AACpC;AAeA,IAAO,cAAQ,wBAAwB;;;AD1SvC,IAAO,oBAAQ,wBAAwB;","names":["import_tools"]}
|
package/dist/extension.js
CHANGED
|
@@ -4,10 +4,98 @@ import {
|
|
|
4
4
|
DEFAULT_OUTLIT_API_URL,
|
|
5
5
|
defaultToolNames,
|
|
6
6
|
getPublicToolContract,
|
|
7
|
+
isOutlitToolsApiError,
|
|
7
8
|
isPublicToolName,
|
|
8
9
|
piToolNames,
|
|
9
10
|
toolNamesInToolsets
|
|
10
11
|
} from "@outlit/tools";
|
|
12
|
+
|
|
13
|
+
// package.json
|
|
14
|
+
var package_default = {
|
|
15
|
+
name: "@outlit/pi",
|
|
16
|
+
version: "4.0.0",
|
|
17
|
+
description: "Pi package for Outlit customer intelligence tools and skill guidance",
|
|
18
|
+
license: "Apache-2.0",
|
|
19
|
+
author: "Outlit AI",
|
|
20
|
+
repository: {
|
|
21
|
+
type: "git",
|
|
22
|
+
url: "https://github.com/OutlitAI/outlit-sdk.git",
|
|
23
|
+
directory: "packages/pi"
|
|
24
|
+
},
|
|
25
|
+
bugs: {
|
|
26
|
+
url: "https://github.com/OutlitAI/outlit-sdk/issues"
|
|
27
|
+
},
|
|
28
|
+
homepage: "https://docs.outlit.ai/ai-integrations/pi",
|
|
29
|
+
keywords: [
|
|
30
|
+
"outlit",
|
|
31
|
+
"pi",
|
|
32
|
+
"pi-package",
|
|
33
|
+
"agents",
|
|
34
|
+
"ai-agents",
|
|
35
|
+
"mcp",
|
|
36
|
+
"customer-intelligence"
|
|
37
|
+
],
|
|
38
|
+
pi: {
|
|
39
|
+
extensions: [
|
|
40
|
+
"./dist/extension.js"
|
|
41
|
+
],
|
|
42
|
+
skills: [
|
|
43
|
+
"./skills"
|
|
44
|
+
]
|
|
45
|
+
},
|
|
46
|
+
publishConfig: {
|
|
47
|
+
access: "public"
|
|
48
|
+
},
|
|
49
|
+
type: "module",
|
|
50
|
+
main: "./dist/index.cjs",
|
|
51
|
+
module: "./dist/index.js",
|
|
52
|
+
types: "./dist/index.d.ts",
|
|
53
|
+
exports: {
|
|
54
|
+
".": {
|
|
55
|
+
types: "./dist/index.d.ts",
|
|
56
|
+
import: "./dist/index.js",
|
|
57
|
+
require: "./dist/index.cjs",
|
|
58
|
+
default: "./dist/index.js"
|
|
59
|
+
},
|
|
60
|
+
"./extension": {
|
|
61
|
+
types: "./dist/extension.d.ts",
|
|
62
|
+
import: "./dist/extension.js",
|
|
63
|
+
require: "./dist/extension.cjs",
|
|
64
|
+
default: "./dist/extension.js"
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
files: [
|
|
68
|
+
"dist",
|
|
69
|
+
"skills",
|
|
70
|
+
"README.md"
|
|
71
|
+
],
|
|
72
|
+
scripts: {
|
|
73
|
+
build: "tsup",
|
|
74
|
+
dev: "tsup --watch",
|
|
75
|
+
clean: "rm -rf dist .turbo node_modules",
|
|
76
|
+
lint: "biome check . --write",
|
|
77
|
+
format: "biome format --write .",
|
|
78
|
+
typecheck: "tsc --noEmit",
|
|
79
|
+
test: "vitest run"
|
|
80
|
+
},
|
|
81
|
+
dependencies: {
|
|
82
|
+
"@outlit/tools": "^4.0.0"
|
|
83
|
+
},
|
|
84
|
+
peerDependencies: {
|
|
85
|
+
"@mariozechner/pi-coding-agent": "*",
|
|
86
|
+
"@sinclair/typebox": "*"
|
|
87
|
+
},
|
|
88
|
+
devDependencies: {
|
|
89
|
+
"@mariozechner/pi-coding-agent": "^0.67.1",
|
|
90
|
+
"@outlit/typescript-config": "workspace:*",
|
|
91
|
+
"@sinclair/typebox": "^0.34.41",
|
|
92
|
+
tsup: "^8.5.1",
|
|
93
|
+
typescript: "^5.9.3",
|
|
94
|
+
vitest: "^4.0.18"
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
// src/index.ts
|
|
11
99
|
import {
|
|
12
100
|
analyticalToolNames,
|
|
13
101
|
defaultToolNames as defaultToolNames2,
|
|
@@ -18,7 +106,13 @@ import {
|
|
|
18
106
|
} from "@outlit/tools";
|
|
19
107
|
var OUTLIT_API_KEY_ENV = "OUTLIT_API_KEY";
|
|
20
108
|
var OUTLIT_API_URL_ENV = "OUTLIT_API_URL";
|
|
109
|
+
var OUTLIT_PI_CLIENT = `@outlit/pi/${package_default.version}`;
|
|
21
110
|
var piToolNameSet = new Set(piToolNames);
|
|
111
|
+
var piDefaultToolNames = [
|
|
112
|
+
...defaultToolNames,
|
|
113
|
+
"outlit_list_toolsets",
|
|
114
|
+
"outlit_load_toolset"
|
|
115
|
+
];
|
|
22
116
|
function createOutlitPiExtension(options = {}) {
|
|
23
117
|
return function outlitPiExtension(pi) {
|
|
24
118
|
for (const tool of createOutlitPiTools(options)) {
|
|
@@ -50,12 +144,23 @@ function createOutlitPiTool(toolName, options = {}) {
|
|
|
50
144
|
apiKey: resolveApiKey(options),
|
|
51
145
|
baseUrl: resolveBaseUrl(options),
|
|
52
146
|
fetch: options.fetch,
|
|
147
|
+
client: OUTLIT_PI_CLIENT,
|
|
53
148
|
onResponse: (info) => {
|
|
54
149
|
responseInfo = info;
|
|
55
150
|
}
|
|
56
151
|
});
|
|
57
|
-
const
|
|
58
|
-
|
|
152
|
+
const input = normalizeToolInput(params);
|
|
153
|
+
try {
|
|
154
|
+
const result = await client.callTool(toolName, input);
|
|
155
|
+
return formatToolResult(toolName, result, responseInfo);
|
|
156
|
+
} catch (error) {
|
|
157
|
+
return formatToolError(
|
|
158
|
+
toolName,
|
|
159
|
+
toToolError(error, responseInfo),
|
|
160
|
+
responseNotices(responseInfo),
|
|
161
|
+
responseInfo
|
|
162
|
+
);
|
|
163
|
+
}
|
|
59
164
|
}
|
|
60
165
|
};
|
|
61
166
|
}
|
|
@@ -71,7 +176,7 @@ function formatOutlitToolLabel(toolName) {
|
|
|
71
176
|
}
|
|
72
177
|
function resolveToolNames(options) {
|
|
73
178
|
const names = [
|
|
74
|
-
...options.toolNames ?? (options.toolsets ? [] :
|
|
179
|
+
...options.toolNames ?? (options.toolsets ? [] : piDefaultToolNames),
|
|
75
180
|
...options.toolsets ? toolNamesInToolsets(options.toolsets) : []
|
|
76
181
|
];
|
|
77
182
|
return [...new Set(names)].map((name) => {
|
|
@@ -111,6 +216,35 @@ function responseNotices(info) {
|
|
|
111
216
|
...info.notices
|
|
112
217
|
];
|
|
113
218
|
}
|
|
219
|
+
function toToolError(error, info) {
|
|
220
|
+
if (isOutlitToolsApiError(error)) {
|
|
221
|
+
if (error.envelope) return { ...error.envelope, status: error.status };
|
|
222
|
+
return {
|
|
223
|
+
message: error.message,
|
|
224
|
+
retryable: error.status === 429 || error.status >= 500,
|
|
225
|
+
status: error.status,
|
|
226
|
+
...error.requestId ?? info?.requestId ? { requestId: error.requestId ?? info?.requestId } : {}
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
return { message: error instanceof Error ? error.message : String(error), retryable: true };
|
|
230
|
+
}
|
|
231
|
+
function formatToolError(toolName, error, notices, info) {
|
|
232
|
+
const result = { error };
|
|
233
|
+
return {
|
|
234
|
+
content: [
|
|
235
|
+
{ type: "text", text: JSON.stringify(result, null, 2) },
|
|
236
|
+
...notices.length > 0 ? [{ type: "text", text: `Notice: ${notices.join(" ")}` }] : []
|
|
237
|
+
],
|
|
238
|
+
details: { toolName, result, error, ...responseIds(info, error.requestId) }
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
function responseIds(info, fallbackRequestId) {
|
|
242
|
+
const requestId = info?.requestId ?? fallbackRequestId;
|
|
243
|
+
return {
|
|
244
|
+
...requestId ? { requestId } : {},
|
|
245
|
+
...info?.version ? { version: info.version } : {}
|
|
246
|
+
};
|
|
247
|
+
}
|
|
114
248
|
function formatToolResult(toolName, result, info) {
|
|
115
249
|
const notices = responseNotices(info);
|
|
116
250
|
return {
|
|
@@ -121,7 +255,8 @@ function formatToolResult(toolName, result, info) {
|
|
|
121
255
|
],
|
|
122
256
|
details: {
|
|
123
257
|
toolName,
|
|
124
|
-
result
|
|
258
|
+
result,
|
|
259
|
+
...responseIds(info)
|
|
125
260
|
}
|
|
126
261
|
};
|
|
127
262
|
}
|
package/dist/extension.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/extension.ts"],"sourcesContent":["import type { AgentToolResult, ExtensionAPI, ToolDefinition } from \"@mariozechner/pi-coding-agent\"\nimport {\n createOutlitClient,\n DEFAULT_OUTLIT_API_URL,\n defaultToolNames,\n getPublicToolContract,\n isPublicToolName,\n type OutlitToolsFetch,\n type OutlitToolsResponseInfo,\n type PiToolName,\n piToolNames,\n type ToolsetName,\n toolNamesInToolsets,\n} from \"@outlit/tools\"\nimport type { TSchema } from \"@sinclair/typebox\"\n\nexport const OUTLIT_API_KEY_ENV = \"OUTLIT_API_KEY\"\nexport const OUTLIT_API_URL_ENV = \"OUTLIT_API_URL\"\n\nconst piToolNameSet = new Set<string>(piToolNames)\n\nexport type OutlitPiExtensionOptions = {\n apiKey?: string\n baseUrl?: string\n fetch?: OutlitToolsFetch\n toolNames?: readonly PiToolName[]\n /**\n * Register every tool in these Core toolsets (core, work, identity, admin, meta). With `toolNames`\n * too, both apply; with neither, the default read-only tools are registered.\n */\n toolsets?: readonly ToolsetName[]\n}\n\nexport type OutlitPiRegistry = Pick<ExtensionAPI, \"registerTool\">\n\nexport type OutlitPiToolDetails = {\n toolName: PiToolName\n result: unknown\n}\n\nexport type OutlitPiToolDefinition = ToolDefinition<TSchema, OutlitPiToolDetails>\n\nexport function createOutlitPiExtension(options: OutlitPiExtensionOptions = {}) {\n return function outlitPiExtension(pi: OutlitPiRegistry) {\n for (const tool of createOutlitPiTools(options)) {\n pi.registerTool(tool)\n }\n }\n}\n\nexport function createOutlitPiTools(\n options: OutlitPiExtensionOptions = {},\n): OutlitPiToolDefinition[] {\n return resolveToolNames(options).map((toolName) => createOutlitPiTool(toolName, options))\n}\n\nexport function createOutlitPiTool(\n toolName: PiToolName,\n options: OutlitPiExtensionOptions = {},\n): OutlitPiToolDefinition {\n if (!isPublicToolName(toolName)) {\n throw new Error(`Unknown Outlit public tool: ${toolName}`)\n }\n if (!piToolNameSet.has(toolName)) {\n throw new Error(`Tool is not available in @outlit/pi: ${toolName}`)\n }\n\n const contract = getPublicToolContract(toolName)\n const label = formatOutlitToolLabel(toolName)\n\n return {\n name: toolName,\n label,\n description: contract.description,\n promptSnippet: `${label}: ${firstLine(contract.description)}`,\n parameters: toPiToolParameters(contract.inputSchema),\n async execute(_toolCallId, params) {\n let responseInfo: OutlitToolsResponseInfo | undefined\n const client = createOutlitClient({\n apiKey: resolveApiKey(options),\n baseUrl: resolveBaseUrl(options),\n fetch: options.fetch,\n onResponse: (info) => {\n responseInfo = info\n },\n })\n const result = await client.callTool(toolName, normalizeToolInput(params))\n\n return formatToolResult(toolName, result, responseInfo)\n },\n }\n}\n\nfunction toPiToolParameters(inputSchema: unknown): TSchema {\n if (inputSchema === null || typeof inputSchema !== \"object\" || Array.isArray(inputSchema)) {\n return inputSchema as TSchema\n }\n\n const { $schema: _schema, ...schema } = inputSchema as Record<string, unknown>\n return schema as unknown as TSchema\n}\n\nexport function formatOutlitToolLabel(toolName: PiToolName): string {\n return toolName\n .split(\"_\")\n .map((part) => part.charAt(0).toUpperCase() + part.slice(1))\n .join(\" \")\n}\n\nfunction resolveToolNames(options: OutlitPiExtensionOptions): PiToolName[] {\n const names: readonly string[] = [\n ...(options.toolNames ?? (options.toolsets ? [] : defaultToolNames)),\n ...(options.toolsets ? toolNamesInToolsets(options.toolsets) : []),\n ]\n\n return [...new Set(names)].map((name) => {\n if (!isPublicToolName(name)) {\n throw new Error(`Unknown Outlit public tool: ${name}`)\n }\n\n return name as PiToolName\n })\n}\n\nfunction resolveApiKey(options: OutlitPiExtensionOptions): string {\n const apiKey = normalizeString(options.apiKey) ?? normalizeString(process.env[OUTLIT_API_KEY_ENV])\n\n if (!apiKey) {\n throw new Error(`${OUTLIT_API_KEY_ENV} is required to use @outlit/pi tools`)\n }\n\n return apiKey\n}\n\nfunction resolveBaseUrl(options: OutlitPiExtensionOptions): string {\n return (\n normalizeString(options.baseUrl) ??\n normalizeString(process.env[OUTLIT_API_URL_ENV]) ??\n DEFAULT_OUTLIT_API_URL\n )\n}\n\nfunction normalizeString(value: string | undefined): string | undefined {\n const trimmed = value?.trim()\n return trimmed ? trimmed : undefined\n}\n\nfunction normalizeToolInput(params: unknown): Record<string, unknown> {\n if (params === undefined) {\n return {}\n }\n\n if (params === null || typeof params !== \"object\" || Array.isArray(params)) {\n throw new TypeError(\"Outlit Pi tool input must be an object\")\n }\n\n return params as Record<string, unknown>\n}\n\n/** What the gateway said beside the result, as sentences for the agent: a deprecation, then notices. */\nfunction responseNotices(info: OutlitToolsResponseInfo | undefined): string[] {\n if (!info) return []\n return [\n ...(info.deprecation ? [`${info.deprecation.message} (until ${info.deprecation.until})`] : []),\n ...info.notices,\n ]\n}\n\nfunction formatToolResult(\n toolName: PiToolName,\n result: unknown,\n info?: OutlitToolsResponseInfo,\n): AgentToolResult<OutlitPiToolDetails> {\n const notices = responseNotices(info)\n return {\n content: [\n { type: \"text\", text: JSON.stringify(result, null, 2) ?? String(result) },\n // After the result, so a reader of the first block still gets the JSON alone.\n ...(notices.length > 0\n ? [{ type: \"text\" as const, text: `Notice: ${notices.join(\" \")}` }]\n : []),\n ],\n details: {\n toolName,\n result,\n },\n }\n}\n\nfunction firstLine(value: string): string {\n return value.split(\"\\n\", 1)[0] ?? value\n}\n\nexport type { PiToolName } from \"@outlit/tools\"\n/** @deprecated Use PiToolName. */\nexport type PublicToolName = PiToolName\nexport type { ToolsetName } from \"@outlit/tools\"\nexport {\n analyticalToolNames,\n defaultToolNames,\n piToolNames,\n piToolNames as allPublicToolNames,\n sqlToolNames,\n toolsetNames,\n} from \"@outlit/tools\"\n\nexport default createOutlitPiExtension()\n","import { createOutlitPiExtension } from \"./index.js\"\n\nexport default createOutlitPiExtension()\n"],"mappings":";AACA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAIA;AAAA,EAEA;AAAA,OACK;AAwLP;AAAA,EACE;AAAA,EACA,oBAAAA;AAAA,EACA,eAAAC;AAAA,EACe,eAAfA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AA5LA,IAAM,qBAAqB;AAC3B,IAAM,qBAAqB;AAElC,IAAM,gBAAgB,IAAI,IAAY,WAAW;AAuB1C,SAAS,wBAAwB,UAAoC,CAAC,GAAG;AAC9E,SAAO,SAAS,kBAAkB,IAAsB;AACtD,eAAW,QAAQ,oBAAoB,OAAO,GAAG;AAC/C,SAAG,aAAa,IAAI;AAAA,IACtB;AAAA,EACF;AACF;AAEO,SAAS,oBACd,UAAoC,CAAC,GACX;AAC1B,SAAO,iBAAiB,OAAO,EAAE,IAAI,CAAC,aAAa,mBAAmB,UAAU,OAAO,CAAC;AAC1F;AAEO,SAAS,mBACd,UACA,UAAoC,CAAC,GACb;AACxB,MAAI,CAAC,iBAAiB,QAAQ,GAAG;AAC/B,UAAM,IAAI,MAAM,+BAA+B,QAAQ,EAAE;AAAA,EAC3D;AACA,MAAI,CAAC,cAAc,IAAI,QAAQ,GAAG;AAChC,UAAM,IAAI,MAAM,wCAAwC,QAAQ,EAAE;AAAA,EACpE;AAEA,QAAM,WAAW,sBAAsB,QAAQ;AAC/C,QAAM,QAAQ,sBAAsB,QAAQ;AAE5C,SAAO;AAAA,IACL,MAAM;AAAA,IACN;AAAA,IACA,aAAa,SAAS;AAAA,IACtB,eAAe,GAAG,KAA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M,MAAM,CAAC,EAAE,CAAC,KAAK;AACpC;AAeA,IAAO,cAAQ,wBAAwB;;;AC5MvC,IAAO,oBAAQ,wBAAwB;","names":["defaultToolNames","piToolNames"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../package.json","../src/extension.ts"],"sourcesContent":["import type { AgentToolResult, ExtensionAPI, ToolDefinition } from \"@mariozechner/pi-coding-agent\"\nimport {\n createOutlitClient,\n DEFAULT_OUTLIT_API_URL,\n defaultToolNames,\n getPublicToolContract,\n isOutlitToolsApiError,\n isPublicToolName,\n type OutlitToolsFetch,\n type OutlitToolsResponseInfo,\n type PiToolName,\n piToolNames,\n type ToolGatewayErrorEnvelope,\n type ToolsetName,\n toolNamesInToolsets,\n} from \"@outlit/tools\"\nimport type { TSchema } from \"@sinclair/typebox\"\nimport pkg from \"../package.json\" with { type: \"json\" }\n\nexport const OUTLIT_API_KEY_ENV = \"OUTLIT_API_KEY\"\nexport const OUTLIT_API_URL_ENV = \"OUTLIT_API_URL\"\n\n/** Sent as `x-outlit-client`, so Core can tell a Pi extension below a release's minimum version. */\nexport const OUTLIT_PI_CLIENT = `@outlit/pi/${pkg.version}`\n\nconst piToolNameSet = new Set<string>(piToolNames)\n\n/**\n * What the extension registers with no options: Core's default customer intelligence tools, plus the\n * two read-only toolset tools, so an agent that needs a tool outside this list can find out which\n * toolset holds it and tell the user to enable it (the `toolsets` option below). Pi registers tools\n * when the session starts, so loading a toolset never adds callable tools mid-session.\n */\nexport const piDefaultToolNames: readonly PiToolName[] = [\n ...defaultToolNames,\n \"outlit_list_toolsets\",\n \"outlit_load_toolset\",\n]\n\nexport type OutlitPiExtensionOptions = {\n apiKey?: string\n baseUrl?: string\n fetch?: OutlitToolsFetch\n toolNames?: readonly PiToolName[]\n /**\n * Register every tool in these Core toolsets (core, work, identity, admin, meta). With `toolNames`\n * too, both apply; with neither, the default read-only tools are registered.\n */\n toolsets?: readonly ToolsetName[]\n}\n\nexport type OutlitPiRegistry = Pick<ExtensionAPI, \"registerTool\">\n\n/**\n * What a failed call hands the agent: the gateway's whole error envelope (`code`, `message`,\n * `retryable`, `requestId`, and when present `next`, `missingPermission`, `validationIssues`,\n * `retryAfterSeconds`), plus the HTTP `status` when there was a response. A failure with no envelope\n * (a proxy's HTML error page, a dropped connection) carries a `message` and `retryable` only.\n */\nexport type OutlitPiToolError = Partial<ToolGatewayErrorEnvelope> & {\n message: string\n retryable: boolean\n status?: number\n}\n\nexport type OutlitPiToolDetails = {\n toolName: PiToolName\n /** The tool's result; `{ error }` when the call failed (see `error`). */\n result: unknown\n /** Set when the call failed at the gateway or the network; the agent sees it as the tool result. */\n error?: OutlitPiToolError\n /** Core's `outlit-request-id` for this call, success or failure: quote it when reporting a problem. */\n requestId?: string\n /** Core's `outlit-version`: the dated output version that answered. */\n version?: string\n}\n\nexport type OutlitPiToolDefinition = ToolDefinition<TSchema, OutlitPiToolDetails>\n\nexport function createOutlitPiExtension(options: OutlitPiExtensionOptions = {}) {\n return function outlitPiExtension(pi: OutlitPiRegistry) {\n for (const tool of createOutlitPiTools(options)) {\n pi.registerTool(tool)\n }\n }\n}\n\nexport function createOutlitPiTools(\n options: OutlitPiExtensionOptions = {},\n): OutlitPiToolDefinition[] {\n return resolveToolNames(options).map((toolName) => createOutlitPiTool(toolName, options))\n}\n\nexport function createOutlitPiTool(\n toolName: PiToolName,\n options: OutlitPiExtensionOptions = {},\n): OutlitPiToolDefinition {\n if (!isPublicToolName(toolName)) {\n throw new Error(`Unknown Outlit public tool: ${toolName}`)\n }\n if (!piToolNameSet.has(toolName)) {\n throw new Error(`Tool is not available in @outlit/pi: ${toolName}`)\n }\n\n const contract = getPublicToolContract(toolName)\n const label = formatOutlitToolLabel(toolName)\n\n return {\n name: toolName,\n label,\n description: contract.description,\n promptSnippet: `${label}: ${firstLine(contract.description)}`,\n parameters: toPiToolParameters(contract.inputSchema),\n async execute(_toolCallId, params) {\n let responseInfo: OutlitToolsResponseInfo | undefined\n const client = createOutlitClient({\n apiKey: resolveApiKey(options),\n baseUrl: resolveBaseUrl(options),\n fetch: options.fetch,\n client: OUTLIT_PI_CLIENT,\n onResponse: (info) => {\n responseInfo = info\n },\n })\n const input = normalizeToolInput(params)\n try {\n const result = await client.callTool(toolName, input)\n return formatToolResult(toolName, result, responseInfo)\n } catch (error) {\n // A failed call is something the agent can act on, not a crash: hand it the envelope.\n return formatToolError(\n toolName,\n toToolError(error, responseInfo),\n responseNotices(responseInfo),\n responseInfo,\n )\n }\n },\n }\n}\n\nfunction toPiToolParameters(inputSchema: unknown): TSchema {\n if (inputSchema === null || typeof inputSchema !== \"object\" || Array.isArray(inputSchema)) {\n return inputSchema as TSchema\n }\n\n const { $schema: _schema, ...schema } = inputSchema as Record<string, unknown>\n return schema as unknown as TSchema\n}\n\nexport function formatOutlitToolLabel(toolName: PiToolName): string {\n return toolName\n .split(\"_\")\n .map((part) => part.charAt(0).toUpperCase() + part.slice(1))\n .join(\" \")\n}\n\nfunction resolveToolNames(options: OutlitPiExtensionOptions): PiToolName[] {\n const names: readonly string[] = [\n ...(options.toolNames ?? (options.toolsets ? [] : piDefaultToolNames)),\n ...(options.toolsets ? toolNamesInToolsets(options.toolsets) : []),\n ]\n\n return [...new Set(names)].map((name) => {\n if (!isPublicToolName(name)) {\n throw new Error(`Unknown Outlit public tool: ${name}`)\n }\n\n return name as PiToolName\n })\n}\n\nfunction resolveApiKey(options: OutlitPiExtensionOptions): string {\n const apiKey = normalizeString(options.apiKey) ?? normalizeString(process.env[OUTLIT_API_KEY_ENV])\n\n if (!apiKey) {\n throw new Error(`${OUTLIT_API_KEY_ENV} is required to use @outlit/pi tools`)\n }\n\n return apiKey\n}\n\nfunction resolveBaseUrl(options: OutlitPiExtensionOptions): string {\n return (\n normalizeString(options.baseUrl) ??\n normalizeString(process.env[OUTLIT_API_URL_ENV]) ??\n DEFAULT_OUTLIT_API_URL\n )\n}\n\nfunction normalizeString(value: string | undefined): string | undefined {\n const trimmed = value?.trim()\n return trimmed ? trimmed : undefined\n}\n\nfunction normalizeToolInput(params: unknown): Record<string, unknown> {\n if (params === undefined) {\n return {}\n }\n\n if (params === null || typeof params !== \"object\" || Array.isArray(params)) {\n throw new TypeError(\"Outlit Pi tool input must be an object\")\n }\n\n return params as Record<string, unknown>\n}\n\n/** What the gateway said beside the result, as sentences for the agent: a deprecation, then notices. */\nfunction responseNotices(info: OutlitToolsResponseInfo | undefined): string[] {\n if (!info) return []\n return [\n ...(info.deprecation ? [`${info.deprecation.message} (until ${info.deprecation.until})`] : []),\n ...info.notices,\n ]\n}\n\nfunction toToolError(error: unknown, info?: OutlitToolsResponseInfo): OutlitPiToolError {\n if (isOutlitToolsApiError(error)) {\n if (error.envelope) return { ...error.envelope, status: error.status }\n return {\n message: error.message,\n retryable: error.status === 429 || error.status >= 500,\n status: error.status,\n ...((error.requestId ?? info?.requestId)\n ? { requestId: error.requestId ?? info?.requestId }\n : {}),\n }\n }\n // fetch rejecting (offline, DNS, reset) or a 200 whose body was not JSON.\n return { message: error instanceof Error ? error.message : String(error), retryable: true }\n}\n\nfunction formatToolError(\n toolName: PiToolName,\n error: OutlitPiToolError,\n notices: string[],\n info?: OutlitToolsResponseInfo,\n): AgentToolResult<OutlitPiToolDetails> {\n const result = { error }\n return {\n content: [\n { type: \"text\", text: JSON.stringify(result, null, 2) },\n ...(notices.length > 0\n ? [{ type: \"text\" as const, text: `Notice: ${notices.join(\" \")}` }]\n : []),\n ],\n details: { toolName, result, error, ...responseIds(info, error.requestId) },\n }\n}\n\nfunction responseIds(\n info: OutlitToolsResponseInfo | undefined,\n fallbackRequestId?: string,\n): { requestId?: string; version?: string } {\n const requestId = info?.requestId ?? fallbackRequestId\n return {\n ...(requestId ? { requestId } : {}),\n ...(info?.version ? { version: info.version } : {}),\n }\n}\n\nfunction formatToolResult(\n toolName: PiToolName,\n result: unknown,\n info?: OutlitToolsResponseInfo,\n): AgentToolResult<OutlitPiToolDetails> {\n const notices = responseNotices(info)\n return {\n content: [\n { type: \"text\", text: JSON.stringify(result, null, 2) ?? String(result) },\n // After the result, so a reader of the first block still gets the JSON alone.\n ...(notices.length > 0\n ? [{ type: \"text\" as const, text: `Notice: ${notices.join(\" \")}` }]\n : []),\n ],\n details: {\n toolName,\n result,\n ...responseIds(info),\n },\n }\n}\n\nfunction firstLine(value: string): string {\n return value.split(\"\\n\", 1)[0] ?? value\n}\n\nexport type { PiToolName } from \"@outlit/tools\"\n/** @deprecated Use PiToolName. */\nexport type PublicToolName = PiToolName\nexport type { ToolsetName } from \"@outlit/tools\"\nexport {\n analyticalToolNames,\n defaultToolNames,\n piToolNames,\n piToolNames as allPublicToolNames,\n sqlToolNames,\n toolsetNames,\n} from \"@outlit/tools\"\n\nexport default createOutlitPiExtension()\n","{\n \"name\": \"@outlit/pi\",\n \"version\": \"4.0.0\",\n \"description\": \"Pi package for Outlit customer intelligence tools and skill guidance\",\n \"license\": \"Apache-2.0\",\n \"author\": \"Outlit AI\",\n \"repository\": {\n \"type\": \"git\",\n \"url\": \"https://github.com/OutlitAI/outlit-sdk.git\",\n \"directory\": \"packages/pi\"\n },\n \"bugs\": {\n \"url\": \"https://github.com/OutlitAI/outlit-sdk/issues\"\n },\n \"homepage\": \"https://docs.outlit.ai/ai-integrations/pi\",\n \"keywords\": [\n \"outlit\",\n \"pi\",\n \"pi-package\",\n \"agents\",\n \"ai-agents\",\n \"mcp\",\n \"customer-intelligence\"\n ],\n \"pi\": {\n \"extensions\": [\n \"./dist/extension.js\"\n ],\n \"skills\": [\n \"./skills\"\n ]\n },\n \"publishConfig\": {\n \"access\": \"public\"\n },\n \"type\": \"module\",\n \"main\": \"./dist/index.cjs\",\n \"module\": \"./dist/index.js\",\n \"types\": \"./dist/index.d.ts\",\n \"exports\": {\n \".\": {\n \"types\": \"./dist/index.d.ts\",\n \"import\": \"./dist/index.js\",\n \"require\": \"./dist/index.cjs\",\n \"default\": \"./dist/index.js\"\n },\n \"./extension\": {\n \"types\": \"./dist/extension.d.ts\",\n \"import\": \"./dist/extension.js\",\n \"require\": \"./dist/extension.cjs\",\n \"default\": \"./dist/extension.js\"\n }\n },\n \"files\": [\n \"dist\",\n \"skills\",\n \"README.md\"\n ],\n \"scripts\": {\n \"build\": \"tsup\",\n \"dev\": \"tsup --watch\",\n \"clean\": \"rm -rf dist .turbo node_modules\",\n \"lint\": \"biome check . --write\",\n \"format\": \"biome format --write .\",\n \"typecheck\": \"tsc --noEmit\",\n \"test\": \"vitest run\"\n },\n \"dependencies\": {\n \"@outlit/tools\": \"^4.0.0\"\n },\n \"peerDependencies\": {\n \"@mariozechner/pi-coding-agent\": \"*\",\n \"@sinclair/typebox\": \"*\"\n },\n \"devDependencies\": {\n \"@mariozechner/pi-coding-agent\": \"^0.67.1\",\n \"@outlit/typescript-config\": \"workspace:*\",\n \"@sinclair/typebox\": \"^0.34.41\",\n \"tsup\": \"^8.5.1\",\n \"typescript\": \"^5.9.3\",\n \"vitest\": \"^4.0.18\"\n }\n}\n","import { createOutlitPiExtension } from \"./index.js\"\n\nexport default createOutlitPiExtension()\n"],"mappings":";AACA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAIA;AAAA,EAGA;AAAA,OACK;;;ACfP;AAAA,EACE,MAAQ;AAAA,EACR,SAAW;AAAA,EACX,aAAe;AAAA,EACf,SAAW;AAAA,EACX,QAAU;AAAA,EACV,YAAc;AAAA,IACZ,MAAQ;AAAA,IACR,KAAO;AAAA,IACP,WAAa;AAAA,EACf;AAAA,EACA,MAAQ;AAAA,IACN,KAAO;AAAA,EACT;AAAA,EACA,UAAY;AAAA,EACZ,UAAY;AAAA,IACV;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAAA,EACA,IAAM;AAAA,IACJ,YAAc;AAAA,MACZ;AAAA,IACF;AAAA,IACA,QAAU;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAAA,EACA,eAAiB;AAAA,IACf,QAAU;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AE,UAAU,IAAI,CAAC;AAAA,IACjC,GAAI,MAAM,UAAU,EAAE,SAAS,KAAK,QAAQ,IAAI,CAAC;AAAA,EACnD;AACF;AAEA,SAAS,iBACP,UACA,QACA,MACsC;AACtC,QAAM,UAAU,gBAAgB,IAAI;AACpC,SAAO;AAAA,IACL,SAAS;AAAA,MACP,EAAE,MAAM,QAAQ,MAAM,KAAK,UAAU,QAAQ,MAAM,CAAC,KAAK,OAAO,MAAM,EAAE;AAAA;AAAA,MAExE,GAAI,QAAQ,SAAS,IACjB,CAAC,EAAE,MAAM,QAAiB,MAAM,WAAW,QAAQ,KAAK,GAAG,CAAC,GAAG,CAAC,IAChE,CAAC;AAAA,IACP;AAAA,IACA,SAAS;AAAA,MACP;AAAA,MACA;AAAA,MACA,GAAG,YAAY,IAAI;AAAA,IACrB;AAAA,EACF;AACF;AAEA,SAAS,UAAU,OAAuB;AACxC,SAAO,MAAM,MAAM,MAAM,CAAC,EAAE,CAAC,KAAK;AACpC;AAeA,IAAO,cAAQ,wBAAwB;;;AE1SvC,IAAO,oBAAQ,wBAAwB;","names":["defaultToolNames","piToolNames"]}
|
package/dist/index.cjs
CHANGED
|
@@ -22,6 +22,7 @@ var src_exports = {};
|
|
|
22
22
|
__export(src_exports, {
|
|
23
23
|
OUTLIT_API_KEY_ENV: () => OUTLIT_API_KEY_ENV,
|
|
24
24
|
OUTLIT_API_URL_ENV: () => OUTLIT_API_URL_ENV,
|
|
25
|
+
OUTLIT_PI_CLIENT: () => OUTLIT_PI_CLIENT,
|
|
25
26
|
allPublicToolNames: () => import_tools2.piToolNames,
|
|
26
27
|
analyticalToolNames: () => import_tools2.analyticalToolNames,
|
|
27
28
|
createOutlitPiExtension: () => createOutlitPiExtension,
|
|
@@ -30,16 +31,110 @@ __export(src_exports, {
|
|
|
30
31
|
default: () => src_default,
|
|
31
32
|
defaultToolNames: () => import_tools2.defaultToolNames,
|
|
32
33
|
formatOutlitToolLabel: () => formatOutlitToolLabel,
|
|
34
|
+
piDefaultToolNames: () => piDefaultToolNames,
|
|
33
35
|
piToolNames: () => import_tools2.piToolNames,
|
|
34
36
|
sqlToolNames: () => import_tools2.sqlToolNames,
|
|
35
37
|
toolsetNames: () => import_tools2.toolsetNames
|
|
36
38
|
});
|
|
37
39
|
module.exports = __toCommonJS(src_exports);
|
|
38
40
|
var import_tools = require("@outlit/tools");
|
|
41
|
+
|
|
42
|
+
// package.json
|
|
43
|
+
var package_default = {
|
|
44
|
+
name: "@outlit/pi",
|
|
45
|
+
version: "4.0.0",
|
|
46
|
+
description: "Pi package for Outlit customer intelligence tools and skill guidance",
|
|
47
|
+
license: "Apache-2.0",
|
|
48
|
+
author: "Outlit AI",
|
|
49
|
+
repository: {
|
|
50
|
+
type: "git",
|
|
51
|
+
url: "https://github.com/OutlitAI/outlit-sdk.git",
|
|
52
|
+
directory: "packages/pi"
|
|
53
|
+
},
|
|
54
|
+
bugs: {
|
|
55
|
+
url: "https://github.com/OutlitAI/outlit-sdk/issues"
|
|
56
|
+
},
|
|
57
|
+
homepage: "https://docs.outlit.ai/ai-integrations/pi",
|
|
58
|
+
keywords: [
|
|
59
|
+
"outlit",
|
|
60
|
+
"pi",
|
|
61
|
+
"pi-package",
|
|
62
|
+
"agents",
|
|
63
|
+
"ai-agents",
|
|
64
|
+
"mcp",
|
|
65
|
+
"customer-intelligence"
|
|
66
|
+
],
|
|
67
|
+
pi: {
|
|
68
|
+
extensions: [
|
|
69
|
+
"./dist/extension.js"
|
|
70
|
+
],
|
|
71
|
+
skills: [
|
|
72
|
+
"./skills"
|
|
73
|
+
]
|
|
74
|
+
},
|
|
75
|
+
publishConfig: {
|
|
76
|
+
access: "public"
|
|
77
|
+
},
|
|
78
|
+
type: "module",
|
|
79
|
+
main: "./dist/index.cjs",
|
|
80
|
+
module: "./dist/index.js",
|
|
81
|
+
types: "./dist/index.d.ts",
|
|
82
|
+
exports: {
|
|
83
|
+
".": {
|
|
84
|
+
types: "./dist/index.d.ts",
|
|
85
|
+
import: "./dist/index.js",
|
|
86
|
+
require: "./dist/index.cjs",
|
|
87
|
+
default: "./dist/index.js"
|
|
88
|
+
},
|
|
89
|
+
"./extension": {
|
|
90
|
+
types: "./dist/extension.d.ts",
|
|
91
|
+
import: "./dist/extension.js",
|
|
92
|
+
require: "./dist/extension.cjs",
|
|
93
|
+
default: "./dist/extension.js"
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
files: [
|
|
97
|
+
"dist",
|
|
98
|
+
"skills",
|
|
99
|
+
"README.md"
|
|
100
|
+
],
|
|
101
|
+
scripts: {
|
|
102
|
+
build: "tsup",
|
|
103
|
+
dev: "tsup --watch",
|
|
104
|
+
clean: "rm -rf dist .turbo node_modules",
|
|
105
|
+
lint: "biome check . --write",
|
|
106
|
+
format: "biome format --write .",
|
|
107
|
+
typecheck: "tsc --noEmit",
|
|
108
|
+
test: "vitest run"
|
|
109
|
+
},
|
|
110
|
+
dependencies: {
|
|
111
|
+
"@outlit/tools": "^4.0.0"
|
|
112
|
+
},
|
|
113
|
+
peerDependencies: {
|
|
114
|
+
"@mariozechner/pi-coding-agent": "*",
|
|
115
|
+
"@sinclair/typebox": "*"
|
|
116
|
+
},
|
|
117
|
+
devDependencies: {
|
|
118
|
+
"@mariozechner/pi-coding-agent": "^0.67.1",
|
|
119
|
+
"@outlit/typescript-config": "workspace:*",
|
|
120
|
+
"@sinclair/typebox": "^0.34.41",
|
|
121
|
+
tsup: "^8.5.1",
|
|
122
|
+
typescript: "^5.9.3",
|
|
123
|
+
vitest: "^4.0.18"
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
// src/index.ts
|
|
39
128
|
var import_tools2 = require("@outlit/tools");
|
|
40
129
|
var OUTLIT_API_KEY_ENV = "OUTLIT_API_KEY";
|
|
41
130
|
var OUTLIT_API_URL_ENV = "OUTLIT_API_URL";
|
|
131
|
+
var OUTLIT_PI_CLIENT = `@outlit/pi/${package_default.version}`;
|
|
42
132
|
var piToolNameSet = new Set(import_tools.piToolNames);
|
|
133
|
+
var piDefaultToolNames = [
|
|
134
|
+
...import_tools.defaultToolNames,
|
|
135
|
+
"outlit_list_toolsets",
|
|
136
|
+
"outlit_load_toolset"
|
|
137
|
+
];
|
|
43
138
|
function createOutlitPiExtension(options = {}) {
|
|
44
139
|
return function outlitPiExtension(pi) {
|
|
45
140
|
for (const tool of createOutlitPiTools(options)) {
|
|
@@ -71,12 +166,23 @@ function createOutlitPiTool(toolName, options = {}) {
|
|
|
71
166
|
apiKey: resolveApiKey(options),
|
|
72
167
|
baseUrl: resolveBaseUrl(options),
|
|
73
168
|
fetch: options.fetch,
|
|
169
|
+
client: OUTLIT_PI_CLIENT,
|
|
74
170
|
onResponse: (info) => {
|
|
75
171
|
responseInfo = info;
|
|
76
172
|
}
|
|
77
173
|
});
|
|
78
|
-
const
|
|
79
|
-
|
|
174
|
+
const input = normalizeToolInput(params);
|
|
175
|
+
try {
|
|
176
|
+
const result = await client.callTool(toolName, input);
|
|
177
|
+
return formatToolResult(toolName, result, responseInfo);
|
|
178
|
+
} catch (error) {
|
|
179
|
+
return formatToolError(
|
|
180
|
+
toolName,
|
|
181
|
+
toToolError(error, responseInfo),
|
|
182
|
+
responseNotices(responseInfo),
|
|
183
|
+
responseInfo
|
|
184
|
+
);
|
|
185
|
+
}
|
|
80
186
|
}
|
|
81
187
|
};
|
|
82
188
|
}
|
|
@@ -92,7 +198,7 @@ function formatOutlitToolLabel(toolName) {
|
|
|
92
198
|
}
|
|
93
199
|
function resolveToolNames(options) {
|
|
94
200
|
const names = [
|
|
95
|
-
...options.toolNames ?? (options.toolsets ? [] :
|
|
201
|
+
...options.toolNames ?? (options.toolsets ? [] : piDefaultToolNames),
|
|
96
202
|
...options.toolsets ? (0, import_tools.toolNamesInToolsets)(options.toolsets) : []
|
|
97
203
|
];
|
|
98
204
|
return [...new Set(names)].map((name) => {
|
|
@@ -132,6 +238,35 @@ function responseNotices(info) {
|
|
|
132
238
|
...info.notices
|
|
133
239
|
];
|
|
134
240
|
}
|
|
241
|
+
function toToolError(error, info) {
|
|
242
|
+
if ((0, import_tools.isOutlitToolsApiError)(error)) {
|
|
243
|
+
if (error.envelope) return { ...error.envelope, status: error.status };
|
|
244
|
+
return {
|
|
245
|
+
message: error.message,
|
|
246
|
+
retryable: error.status === 429 || error.status >= 500,
|
|
247
|
+
status: error.status,
|
|
248
|
+
...error.requestId ?? info?.requestId ? { requestId: error.requestId ?? info?.requestId } : {}
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
return { message: error instanceof Error ? error.message : String(error), retryable: true };
|
|
252
|
+
}
|
|
253
|
+
function formatToolError(toolName, error, notices, info) {
|
|
254
|
+
const result = { error };
|
|
255
|
+
return {
|
|
256
|
+
content: [
|
|
257
|
+
{ type: "text", text: JSON.stringify(result, null, 2) },
|
|
258
|
+
...notices.length > 0 ? [{ type: "text", text: `Notice: ${notices.join(" ")}` }] : []
|
|
259
|
+
],
|
|
260
|
+
details: { toolName, result, error, ...responseIds(info, error.requestId) }
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
function responseIds(info, fallbackRequestId) {
|
|
264
|
+
const requestId = info?.requestId ?? fallbackRequestId;
|
|
265
|
+
return {
|
|
266
|
+
...requestId ? { requestId } : {},
|
|
267
|
+
...info?.version ? { version: info.version } : {}
|
|
268
|
+
};
|
|
269
|
+
}
|
|
135
270
|
function formatToolResult(toolName, result, info) {
|
|
136
271
|
const notices = responseNotices(info);
|
|
137
272
|
return {
|
|
@@ -142,7 +277,8 @@ function formatToolResult(toolName, result, info) {
|
|
|
142
277
|
],
|
|
143
278
|
details: {
|
|
144
279
|
toolName,
|
|
145
|
-
result
|
|
280
|
+
result,
|
|
281
|
+
...responseIds(info)
|
|
146
282
|
}
|
|
147
283
|
};
|
|
148
284
|
}
|
|
@@ -154,6 +290,7 @@ var src_default = createOutlitPiExtension();
|
|
|
154
290
|
0 && (module.exports = {
|
|
155
291
|
OUTLIT_API_KEY_ENV,
|
|
156
292
|
OUTLIT_API_URL_ENV,
|
|
293
|
+
OUTLIT_PI_CLIENT,
|
|
157
294
|
allPublicToolNames,
|
|
158
295
|
analyticalToolNames,
|
|
159
296
|
createOutlitPiExtension,
|
|
@@ -161,6 +298,7 @@ var src_default = createOutlitPiExtension();
|
|
|
161
298
|
createOutlitPiTools,
|
|
162
299
|
defaultToolNames,
|
|
163
300
|
formatOutlitToolLabel,
|
|
301
|
+
piDefaultToolNames,
|
|
164
302
|
piToolNames,
|
|
165
303
|
sqlToolNames,
|
|
166
304
|
toolsetNames
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { AgentToolResult, ExtensionAPI, ToolDefinition } from \"@mariozechner/pi-coding-agent\"\nimport {\n createOutlitClient,\n DEFAULT_OUTLIT_API_URL,\n defaultToolNames,\n getPublicToolContract,\n isPublicToolName,\n type OutlitToolsFetch,\n type OutlitToolsResponseInfo,\n type PiToolName,\n piToolNames,\n type ToolsetName,\n toolNamesInToolsets,\n} from \"@outlit/tools\"\nimport type { TSchema } from \"@sinclair/typebox\"\n\nexport const OUTLIT_API_KEY_ENV = \"OUTLIT_API_KEY\"\nexport const OUTLIT_API_URL_ENV = \"OUTLIT_API_URL\"\n\nconst piToolNameSet = new Set<string>(piToolNames)\n\nexport type OutlitPiExtensionOptions = {\n apiKey?: string\n baseUrl?: string\n fetch?: OutlitToolsFetch\n toolNames?: readonly PiToolName[]\n /**\n * Register every tool in these Core toolsets (core, work, identity, admin, meta). With `toolNames`\n * too, both apply; with neither, the default read-only tools are registered.\n */\n toolsets?: readonly ToolsetName[]\n}\n\nexport type OutlitPiRegistry = Pick<ExtensionAPI, \"registerTool\">\n\nexport type OutlitPiToolDetails = {\n toolName: PiToolName\n result: unknown\n}\n\nexport type OutlitPiToolDefinition = ToolDefinition<TSchema, OutlitPiToolDetails>\n\nexport function createOutlitPiExtension(options: OutlitPiExtensionOptions = {}) {\n return function outlitPiExtension(pi: OutlitPiRegistry) {\n for (const tool of createOutlitPiTools(options)) {\n pi.registerTool(tool)\n }\n }\n}\n\nexport function createOutlitPiTools(\n options: OutlitPiExtensionOptions = {},\n): OutlitPiToolDefinition[] {\n return resolveToolNames(options).map((toolName) => createOutlitPiTool(toolName, options))\n}\n\nexport function createOutlitPiTool(\n toolName: PiToolName,\n options: OutlitPiExtensionOptions = {},\n): OutlitPiToolDefinition {\n if (!isPublicToolName(toolName)) {\n throw new Error(`Unknown Outlit public tool: ${toolName}`)\n }\n if (!piToolNameSet.has(toolName)) {\n throw new Error(`Tool is not available in @outlit/pi: ${toolName}`)\n }\n\n const contract = getPublicToolContract(toolName)\n const label = formatOutlitToolLabel(toolName)\n\n return {\n name: toolName,\n label,\n description: contract.description,\n promptSnippet: `${label}: ${firstLine(contract.description)}`,\n parameters: toPiToolParameters(contract.inputSchema),\n async execute(_toolCallId, params) {\n let responseInfo: OutlitToolsResponseInfo | undefined\n const client = createOutlitClient({\n apiKey: resolveApiKey(options),\n baseUrl: resolveBaseUrl(options),\n fetch: options.fetch,\n onResponse: (info) => {\n responseInfo = info\n },\n })\n const result = await client.callTool(toolName, normalizeToolInput(params))\n\n return formatToolResult(toolName, result, responseInfo)\n },\n }\n}\n\nfunction toPiToolParameters(inputSchema: unknown): TSchema {\n if (inputSchema === null || typeof inputSchema !== \"object\" || Array.isArray(inputSchema)) {\n return inputSchema as TSchema\n }\n\n const { $schema: _schema, ...schema } = inputSchema as Record<string, unknown>\n return schema as unknown as TSchema\n}\n\nexport function formatOutlitToolLabel(toolName: PiToolName): string {\n return toolName\n .split(\"_\")\n .map((part) => part.charAt(0).toUpperCase() + part.slice(1))\n .join(\" \")\n}\n\nfunction resolveToolNames(options: OutlitPiExtensionOptions): PiToolName[] {\n const names: readonly string[] = [\n ...(options.toolNames ?? (options.toolsets ? [] : defaultToolNames)),\n ...(options.toolsets ? toolNamesInToolsets(options.toolsets) : []),\n ]\n\n return [...new Set(names)].map((name) => {\n if (!isPublicToolName(name)) {\n throw new Error(`Unknown Outlit public tool: ${name}`)\n }\n\n return name as PiToolName\n })\n}\n\nfunction resolveApiKey(options: OutlitPiExtensionOptions): string {\n const apiKey = normalizeString(options.apiKey) ?? normalizeString(process.env[OUTLIT_API_KEY_ENV])\n\n if (!apiKey) {\n throw new Error(`${OUTLIT_API_KEY_ENV} is required to use @outlit/pi tools`)\n }\n\n return apiKey\n}\n\nfunction resolveBaseUrl(options: OutlitPiExtensionOptions): string {\n return (\n normalizeString(options.baseUrl) ??\n normalizeString(process.env[OUTLIT_API_URL_ENV]) ??\n DEFAULT_OUTLIT_API_URL\n )\n}\n\nfunction normalizeString(value: string | undefined): string | undefined {\n const trimmed = value?.trim()\n return trimmed ? trimmed : undefined\n}\n\nfunction normalizeToolInput(params: unknown): Record<string, unknown> {\n if (params === undefined) {\n return {}\n }\n\n if (params === null || typeof params !== \"object\" || Array.isArray(params)) {\n throw new TypeError(\"Outlit Pi tool input must be an object\")\n }\n\n return params as Record<string, unknown>\n}\n\n/** What the gateway said beside the result, as sentences for the agent: a deprecation, then notices. */\nfunction responseNotices(info: OutlitToolsResponseInfo | undefined): string[] {\n if (!info) return []\n return [\n ...(info.deprecation ? [`${info.deprecation.message} (until ${info.deprecation.until})`] : []),\n ...info.notices,\n ]\n}\n\nfunction formatToolResult(\n toolName: PiToolName,\n result: unknown,\n info?: OutlitToolsResponseInfo,\n): AgentToolResult<OutlitPiToolDetails> {\n const notices = responseNotices(info)\n return {\n content: [\n { type: \"text\", text: JSON.stringify(result, null, 2) ?? String(result) },\n // After the result, so a reader of the first block still gets the JSON alone.\n ...(notices.length > 0\n ? [{ type: \"text\" as const, text: `Notice: ${notices.join(\" \")}` }]\n : []),\n ],\n details: {\n toolName,\n result,\n },\n }\n}\n\nfunction firstLine(value: string): string {\n return value.split(\"\\n\", 1)[0] ?? value\n}\n\nexport type { PiToolName } from \"@outlit/tools\"\n/** @deprecated Use PiToolName. */\nexport type PublicToolName = PiToolName\nexport type { ToolsetName } from \"@outlit/tools\"\nexport {\n analyticalToolNames,\n defaultToolNames,\n piToolNames,\n piToolNames as allPublicToolNames,\n sqlToolNames,\n toolsetNames,\n} from \"@outlit/tools\"\n\nexport default createOutlitPiExtension()\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAYO;AAwLP,IAAAA,gBAOO;AA5LA,IAAM,qBAAqB;AAC3B,IAAM,qBAAqB;AAElC,IAAM,gBAAgB,IAAI,IAAY,wBAAW;AAuB1C,SAAS,wBAAwB,UAAoC,CAAC,GAAG;AAC9E,SAAO,SAAS,kBAAkB,IAAsB;AACtD,eAAW,QAAQ,oBAAoB,OAAO,GAAG;AAC/C,SAAG,aAAa,IAAI;AAAA,IACtB;AAAA,EACF;AACF;AAEO,SAAS,oBACd,UAAoC,CAAC,GACX;AAC1B,SAAO,iBAAiB,OAAO,EAAE,IAAI,CAAC,aAAa,mBAAmB,UAAU,OAAO,CAAC;AAC1F;AAEO,SAAS,mBACd,UACA,UAAoC,CAAC,GACb;AACxB,MAAI,KAAC,+BAAiB,QAAQ,GAAG;AAC/B,UAAM,IAAI,MAAM,+BAA+B,QAAQ,EAAE;AAAA,EAC3D;AACA,MAAI,CAAC,cAAc,IAAI,QAAQ,GAAG;AAChC,UAAM,IAAI,MAAM,wCAAwC,QAAQ,EAAE;AAAA,EACpE;AAEA,QAAM,eAAW,oCAAsB,QAAQ;AAC/C,QAAM,QAAQ,sBAAsB,QAAQ;AAE5C,SAAO;AAAA,IACL,MAAM;AAAA,IACN;AAAA,IACA,aAAa,SAAS;AAAA,IACtB,eAAe,GAAG,KAAK,KAAK,UAAU,SAAS,WAAW,CAAC;AAAA,IAC3D,YAAY,mBAAmB,SAAS,WAAW;AAAA,IACnD,MAAM,QAAQ,aAAa,QAAQ;AACjC,UAAI;AACJ,YAAM,aA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AgentToolResult, ExtensionAPI, ToolDefinition } from \"@mariozechner/pi-coding-agent\"\nimport {\n createOutlitClient,\n DEFAULT_OUTLIT_API_URL,\n defaultToolNames,\n getPublicToolContract,\n isOutlitToolsApiError,\n isPublicToolName,\n type OutlitToolsFetch,\n type OutlitToolsResponseInfo,\n type PiToolName,\n piToolNames,\n type ToolGatewayErrorEnvelope,\n type ToolsetName,\n toolNamesInToolsets,\n} from \"@outlit/tools\"\nimport type { TSchema } from \"@sinclair/typebox\"\nimport pkg from \"../package.json\" with { type: \"json\" }\n\nexport const OUTLIT_API_KEY_ENV = \"OUTLIT_API_KEY\"\nexport const OUTLIT_API_URL_ENV = \"OUTLIT_API_URL\"\n\n/** Sent as `x-outlit-client`, so Core can tell a Pi extension below a release's minimum version. */\nexport const OUTLIT_PI_CLIENT = `@outlit/pi/${pkg.version}`\n\nconst piToolNameSet = new Set<string>(piToolNames)\n\n/**\n * What the extension registers with no options: Core's default customer intelligence tools, plus the\n * two read-only toolset tools, so an agent that needs a tool outside this list can find out which\n * toolset holds it and tell the user to enable it (the `toolsets` option below). Pi registers tools\n * when the session starts, so loading a toolset never adds callable tools mid-session.\n */\nexport const piDefaultToolNames: readonly PiToolName[] = [\n ...defaultToolNames,\n \"outlit_list_toolsets\",\n \"outlit_load_toolset\",\n]\n\nexport type OutlitPiExtensionOptions = {\n apiKey?: string\n baseUrl?: string\n fetch?: OutlitToolsFetch\n toolNames?: readonly PiToolName[]\n /**\n * Register every tool in these Core toolsets (core, work, identity, admin, meta). With `toolNames`\n * too, both apply; with neither, the default read-only tools are registered.\n */\n toolsets?: readonly ToolsetName[]\n}\n\nexport type OutlitPiRegistry = Pick<ExtensionAPI, \"registerTool\">\n\n/**\n * What a failed call hands the agent: the gateway's whole error envelope (`code`, `message`,\n * `retryable`, `requestId`, and when present `next`, `missingPermission`, `validationIssues`,\n * `retryAfterSeconds`), plus the HTTP `status` when there was a response. A failure with no envelope\n * (a proxy's HTML error page, a dropped connection) carries a `message` and `retryable` only.\n */\nexport type OutlitPiToolError = Partial<ToolGatewayErrorEnvelope> & {\n message: string\n retryable: boolean\n status?: number\n}\n\nexport type OutlitPiToolDetails = {\n toolName: PiToolName\n /** The tool's result; `{ error }` when the call failed (see `error`). */\n result: unknown\n /** Set when the call failed at the gateway or the network; the agent sees it as the tool result. */\n error?: OutlitPiToolError\n /** Core's `outlit-request-id` for this call, success or failure: quote it when reporting a problem. */\n requestId?: string\n /** Core's `outlit-version`: the dated output version that answered. */\n version?: string\n}\n\nexport type OutlitPiToolDefinition = ToolDefinition<TSchema, OutlitPiToolDetails>\n\nexport function createOutlitPiExtension(options: OutlitPiExtensionOptions = {}) {\n return function outlitPiExtension(pi: OutlitPiRegistry) {\n for (const tool of createOutlitPiTools(options)) {\n pi.registerTool(tool)\n }\n }\n}\n\nexport function createOutlitPiTools(\n options: OutlitPiExtensionOptions = {},\n): OutlitPiToolDefinition[] {\n return resolveToolNames(options).map((toolName) => createOutlitPiTool(toolName, options))\n}\n\nexport function createOutlitPiTool(\n toolName: PiToolName,\n options: OutlitPiExtensionOptions = {},\n): OutlitPiToolDefinition {\n if (!isPublicToolName(toolName)) {\n throw new Error(`Unknown Outlit public tool: ${toolName}`)\n }\n if (!piToolNameSet.has(toolName)) {\n throw new Error(`Tool is not available in @outlit/pi: ${toolName}`)\n }\n\n const contract = getPublicToolContract(toolName)\n const label = formatOutlitToolLabel(toolName)\n\n return {\n name: toolName,\n label,\n description: contract.description,\n promptSnippet: `${label}: ${firstLine(contract.description)}`,\n parameters: toPiToolParameters(contract.inputSchema),\n async execute(_toolCallId, params) {\n let responseInfo: OutlitToolsResponseInfo | undefined\n const client = createOutlitClient({\n apiKey: resolveApiKey(options),\n baseUrl: resolveBaseUrl(options),\n fetch: options.fetch,\n client: OUTLIT_PI_CLIENT,\n onResponse: (info) => {\n responseInfo = info\n },\n })\n const input = normalizeToolInput(params)\n try {\n const result = await client.callTool(toolName, input)\n return formatToolResult(toolName, result, responseInfo)\n } catch (error) {\n // A failed call is something the agent can act on, not a crash: hand it the envelope.\n return formatToolError(\n toolName,\n toToolError(error, responseInfo),\n responseNotices(responseInfo),\n responseInfo,\n )\n }\n },\n }\n}\n\nfunction toPiToolParameters(inputSchema: unknown): TSchema {\n if (inputSchema === null || typeof inputSchema !== \"object\" || Array.isArray(inputSchema)) {\n return inputSchema as TSchema\n }\n\n const { $schema: _schema, ...schema } = inputSchema as Record<string, unknown>\n return schema as unknown as TSchema\n}\n\nexport function formatOutlitToolLabel(toolName: PiToolName): string {\n return toolName\n .split(\"_\")\n .map((part) => part.charAt(0).toUpperCase() + part.slice(1))\n .join(\" \")\n}\n\nfunction resolveToolNames(options: OutlitPiExtensionOptions): PiToolName[] {\n const names: readonly string[] = [\n ...(options.toolNames ?? (options.toolsets ? [] : piDefaultToolNames)),\n ...(options.toolsets ? toolNamesInToolsets(options.toolsets) : []),\n ]\n\n return [...new Set(names)].map((name) => {\n if (!isPublicToolName(name)) {\n throw new Error(`Unknown Outlit public tool: ${name}`)\n }\n\n return name as PiToolName\n })\n}\n\nfunction resolveApiKey(options: OutlitPiExtensionOptions): string {\n const apiKey = normalizeString(options.apiKey) ?? normalizeString(process.env[OUTLIT_API_KEY_ENV])\n\n if (!apiKey) {\n throw new Error(`${OUTLIT_API_KEY_ENV} is required to use @outlit/pi tools`)\n }\n\n return apiKey\n}\n\nfunction resolveBaseUrl(options: OutlitPiExtensionOptions): string {\n return (\n normalizeString(options.baseUrl) ??\n normalizeString(process.env[OUTLIT_API_URL_ENV]) ??\n DEFAULT_OUTLIT_API_URL\n )\n}\n\nfunction normalizeString(value: string | undefined): string | undefined {\n const trimmed = value?.trim()\n return trimmed ? trimmed : undefined\n}\n\nfunction normalizeToolInput(params: unknown): Record<string, unknown> {\n if (params === undefined) {\n return {}\n }\n\n if (params === null || typeof params !== \"object\" || Array.isArray(params)) {\n throw new TypeError(\"Outlit Pi tool input must be an object\")\n }\n\n return params as Record<string, unknown>\n}\n\n/** What the gateway said beside the result, as sentences for the agent: a deprecation, then notices. */\nfunction responseNotices(info: OutlitToolsResponseInfo | undefined): string[] {\n if (!info) return []\n return [\n ...(info.deprecation ? [`${info.deprecation.message} (until ${info.deprecation.until})`] : []),\n ...info.notices,\n ]\n}\n\nfunction toToolError(error: unknown, info?: OutlitToolsResponseInfo): OutlitPiToolError {\n if (isOutlitToolsApiError(error)) {\n if (error.envelope) return { ...error.envelope, status: error.status }\n return {\n message: error.message,\n retryable: error.status === 429 || error.status >= 500,\n status: error.status,\n ...((error.requestId ?? info?.requestId)\n ? { requestId: error.requestId ?? info?.requestId }\n : {}),\n }\n }\n // fetch rejecting (offline, DNS, reset) or a 200 whose body was not JSON.\n return { message: error instanceof Error ? error.message : String(error), retryable: true }\n}\n\nfunction formatToolError(\n toolName: PiToolName,\n error: OutlitPiToolError,\n notices: string[],\n info?: OutlitToolsResponseInfo,\n): AgentToolResult<OutlitPiToolDetails> {\n const result = { error }\n return {\n content: [\n { type: \"text\", text: JSON.stringify(result, null, 2) },\n ...(notices.length > 0\n ? [{ type: \"text\" as const, text: `Notice: ${notices.join(\" \")}` }]\n : []),\n ],\n details: { toolName, result, error, ...responseIds(info, error.requestId) },\n }\n}\n\nfunction responseIds(\n info: OutlitToolsResponseInfo | undefined,\n fallbackRequestId?: string,\n): { requestId?: string; version?: string } {\n const requestId = info?.requestId ?? fallbackRequestId\n return {\n ...(requestId ? { requestId } : {}),\n ...(info?.version ? { version: info.version } : {}),\n }\n}\n\nfunction formatToolResult(\n toolName: PiToolName,\n result: unknown,\n info?: OutlitToolsResponseInfo,\n): AgentToolResult<OutlitPiToolDetails> {\n const notices = responseNotices(info)\n return {\n content: [\n { type: \"text\", text: JSON.stringify(result, null, 2) ?? String(result) },\n // After the result, so a reader of the first block still gets the JSON alone.\n ...(notices.length > 0\n ? [{ type: \"text\" as const, text: `Notice: ${notices.join(\" \")}` }]\n : []),\n ],\n details: {\n toolName,\n result,\n ...responseIds(info),\n },\n }\n}\n\nfunction firstLine(value: string): string {\n return value.split(\"\\n\", 1)[0] ?? value\n}\n\nexport type { PiToolName } from \"@outlit/tools\"\n/** @deprecated Use PiToolName. */\nexport type PublicToolName = PiToolName\nexport type { ToolsetName } from \"@outlit/tools\"\nexport {\n analyticalToolNames,\n defaultToolNames,\n piToolNames,\n piToolNames as allPublicToolNames,\n sqlToolNames,\n toolsetNames,\n} from \"@outlit/tools\"\n\nexport default createOutlitPiExtension()\n","{\n \"name\": \"@outlit/pi\",\n \"version\": \"4.0.0\",\n \"description\": \"Pi package for Outlit customer intelligence tools and skill guidance\",\n \"license\": \"Apache-2.0\",\n \"author\": \"Outlit AI\",\n \"repository\": {\n \"type\": \"git\",\n \"url\": \"https://github.com/OutlitAI/outlit-sdk.git\",\n \"directory\": \"packages/pi\"\n },\n \"bugs\": {\n \"url\": \"https://github.com/OutlitAI/outlit-sdk/issues\"\n },\n \"homepage\": \"https://docs.outlit.ai/ai-integrations/pi\",\n \"keywords\": [\n \"outlit\",\n \"pi\",\n \"pi-package\",\n \"agents\",\n \"ai-agents\",\n \"mcp\",\n \"customer-intelligence\"\n ],\n \"pi\": {\n \"extensions\": [\n \"./dist/extension.js\"\n ],\n \"skills\": [\n \"./skills\"\n ]\n },\n \"publishConfig\": {\n \"access\": \"public\"\n },\n \"type\": \"module\",\n \"main\": \"./dist/index.cjs\",\n \"module\": \"./dist/index.js\",\n \"types\": \"./dist/index.d.ts\",\n \"exports\": {\n \".\": {\n \"types\": \"./dist/index.d.ts\",\n \"import\": \"./dist/index.js\",\n \"require\": \"./dist/index.cjs\",\n \"default\": \"./dist/index.js\"\n },\n \"./extension\": {\n \"types\": \"./dist/extension.d.ts\",\n \"import\": \"./dist/extension.js\",\n \"require\": \"./dist/extension.cjs\",\n \"default\": \"./dist/extension.js\"\n }\n },\n \"files\": [\n \"dist\",\n \"skills\",\n \"README.md\"\n ],\n \"scripts\": {\n \"build\": \"tsup\",\n \"dev\": \"tsup --watch\",\n \"clean\": \"rm -rf dist .turbo node_modules\",\n \"lint\": \"biome check . --write\",\n \"format\": \"biome format --write .\",\n \"typecheck\": \"tsc --noEmit\",\n \"test\": \"vitest run\"\n },\n \"dependencies\": {\n \"@outlit/tools\": \"^4.0.0\"\n },\n \"peerDependencies\": {\n \"@mariozechner/pi-coding-agent\": \"*\",\n \"@sinclair/typebox\": \"*\"\n },\n \"devDependencies\": {\n \"@mariozechner/pi-coding-agent\": \"^0.67.1\",\n \"@outlit/typescript-config\": \"workspace:*\",\n \"@sinclair/typebox\": \"^0.34.41\",\n \"tsup\": \"^8.5.1\",\n \"typescript\": \"^5.9.3\",\n \"vitest\": \"^4.0.18\"\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAcO;;;ACfP;AAAA,EACE,MAAQ;AAAA,EACR,SAAW;AAAA,EACX,aAAe;AAAA,EACf,SAAW;AAAA,EACX,QAAU;AAAA,EACV,YAAc;AAAA,IACZ,MAAQ;AAAA,IACR,KAAO;AAAA,IACP,WAAa;AAAA,EACf;AAAA,EACA,MAAQ;AAAA,IACN,KAAO;AAAA,EACT;AAAA,EACA,UAAY;AAAA,EACZ,UAAY;AAAA,IACV;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAAA,EACA,IAAM;AAAA,IACJ,YAAc;AAAA,MACZ;AAAA,IACF;AAAA,IACA,QAAU;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAAA,EACA,eAAiB;AAAA,IACf,QAAU;AAAA,EACZ;AAAA,EACA,MAAQ;AAAA,EACR,MAAQ;AAAA,EACR,QAAU;AAAA,EACV,OAAS;AAAA,EACT,SAAW;AAAA,IACT,KAAK;AAAA,MACH,OAAS;AAAA,MACT,QAAU;AAAA,MACV,SAAW;AAAA,MACX,SAAW;AAAA,IACb;AAAA,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AM,EAAE;AAAA;AAAA,MAExE,GAAI,QAAQ,SAAS,IACjB,CAAC,EAAE,MAAM,QAAiB,MAAM,WAAW,QAAQ,KAAK,GAAG,CAAC,GAAG,CAAC,IAChE,CAAC;AAAA,IACP;AAAA,IACA,SAAS;AAAA,MACP;AAAA,MACA;AAAA,MACA,GAAG,YAAY,IAAI;AAAA,IACrB;AAAA,EACF;AACF;AAEA,SAAS,UAAU,OAAuB;AACxC,SAAO,MAAM,MAAM,MAAM,CAAC,EAAE,CAAC,KAAK;AACpC;AAeA,IAAO,cAAQ,wBAAwB;","names":["import_tools"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,10 +1,19 @@
|
|
|
1
1
|
import { ExtensionAPI, ToolDefinition } from '@mariozechner/pi-coding-agent';
|
|
2
|
-
import { OutlitToolsFetch, PiToolName, ToolsetName } from '@outlit/tools';
|
|
2
|
+
import { OutlitToolsFetch, PiToolName, ToolsetName, ToolGatewayErrorEnvelope } from '@outlit/tools';
|
|
3
3
|
export { PiToolName, ToolsetName, piToolNames as allPublicToolNames, analyticalToolNames, defaultToolNames, piToolNames, sqlToolNames, toolsetNames } from '@outlit/tools';
|
|
4
4
|
import { TSchema } from '@sinclair/typebox';
|
|
5
5
|
|
|
6
6
|
declare const OUTLIT_API_KEY_ENV = "OUTLIT_API_KEY";
|
|
7
7
|
declare const OUTLIT_API_URL_ENV = "OUTLIT_API_URL";
|
|
8
|
+
/** Sent as `x-outlit-client`, so Core can tell a Pi extension below a release's minimum version. */
|
|
9
|
+
declare const OUTLIT_PI_CLIENT: string;
|
|
10
|
+
/**
|
|
11
|
+
* What the extension registers with no options: Core's default customer intelligence tools, plus the
|
|
12
|
+
* two read-only toolset tools, so an agent that needs a tool outside this list can find out which
|
|
13
|
+
* toolset holds it and tell the user to enable it (the `toolsets` option below). Pi registers tools
|
|
14
|
+
* when the session starts, so loading a toolset never adds callable tools mid-session.
|
|
15
|
+
*/
|
|
16
|
+
declare const piDefaultToolNames: readonly PiToolName[];
|
|
8
17
|
type OutlitPiExtensionOptions = {
|
|
9
18
|
apiKey?: string;
|
|
10
19
|
baseUrl?: string;
|
|
@@ -17,9 +26,27 @@ type OutlitPiExtensionOptions = {
|
|
|
17
26
|
toolsets?: readonly ToolsetName[];
|
|
18
27
|
};
|
|
19
28
|
type OutlitPiRegistry = Pick<ExtensionAPI, "registerTool">;
|
|
29
|
+
/**
|
|
30
|
+
* What a failed call hands the agent: the gateway's whole error envelope (`code`, `message`,
|
|
31
|
+
* `retryable`, `requestId`, and when present `next`, `missingPermission`, `validationIssues`,
|
|
32
|
+
* `retryAfterSeconds`), plus the HTTP `status` when there was a response. A failure with no envelope
|
|
33
|
+
* (a proxy's HTML error page, a dropped connection) carries a `message` and `retryable` only.
|
|
34
|
+
*/
|
|
35
|
+
type OutlitPiToolError = Partial<ToolGatewayErrorEnvelope> & {
|
|
36
|
+
message: string;
|
|
37
|
+
retryable: boolean;
|
|
38
|
+
status?: number;
|
|
39
|
+
};
|
|
20
40
|
type OutlitPiToolDetails = {
|
|
21
41
|
toolName: PiToolName;
|
|
42
|
+
/** The tool's result; `{ error }` when the call failed (see `error`). */
|
|
22
43
|
result: unknown;
|
|
44
|
+
/** Set when the call failed at the gateway or the network; the agent sees it as the tool result. */
|
|
45
|
+
error?: OutlitPiToolError;
|
|
46
|
+
/** Core's `outlit-request-id` for this call, success or failure: quote it when reporting a problem. */
|
|
47
|
+
requestId?: string;
|
|
48
|
+
/** Core's `outlit-version`: the dated output version that answered. */
|
|
49
|
+
version?: string;
|
|
23
50
|
};
|
|
24
51
|
type OutlitPiToolDefinition = ToolDefinition<TSchema, OutlitPiToolDetails>;
|
|
25
52
|
declare function createOutlitPiExtension(options?: OutlitPiExtensionOptions): (pi: OutlitPiRegistry) => void;
|
|
@@ -32,4 +59,4 @@ type PublicToolName = PiToolName;
|
|
|
32
59
|
|
|
33
60
|
declare const _default: (pi: OutlitPiRegistry) => void;
|
|
34
61
|
|
|
35
|
-
export { OUTLIT_API_KEY_ENV, OUTLIT_API_URL_ENV, type OutlitPiExtensionOptions, type OutlitPiRegistry, type OutlitPiToolDefinition, type OutlitPiToolDetails, type PublicToolName, createOutlitPiExtension, createOutlitPiTool, createOutlitPiTools, _default as default, formatOutlitToolLabel };
|
|
62
|
+
export { OUTLIT_API_KEY_ENV, OUTLIT_API_URL_ENV, OUTLIT_PI_CLIENT, type OutlitPiExtensionOptions, type OutlitPiRegistry, type OutlitPiToolDefinition, type OutlitPiToolDetails, type OutlitPiToolError, type PublicToolName, createOutlitPiExtension, createOutlitPiTool, createOutlitPiTools, _default as default, formatOutlitToolLabel, piDefaultToolNames };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,19 @@
|
|
|
1
1
|
import { ExtensionAPI, ToolDefinition } from '@mariozechner/pi-coding-agent';
|
|
2
|
-
import { OutlitToolsFetch, PiToolName, ToolsetName } from '@outlit/tools';
|
|
2
|
+
import { OutlitToolsFetch, PiToolName, ToolsetName, ToolGatewayErrorEnvelope } from '@outlit/tools';
|
|
3
3
|
export { PiToolName, ToolsetName, piToolNames as allPublicToolNames, analyticalToolNames, defaultToolNames, piToolNames, sqlToolNames, toolsetNames } from '@outlit/tools';
|
|
4
4
|
import { TSchema } from '@sinclair/typebox';
|
|
5
5
|
|
|
6
6
|
declare const OUTLIT_API_KEY_ENV = "OUTLIT_API_KEY";
|
|
7
7
|
declare const OUTLIT_API_URL_ENV = "OUTLIT_API_URL";
|
|
8
|
+
/** Sent as `x-outlit-client`, so Core can tell a Pi extension below a release's minimum version. */
|
|
9
|
+
declare const OUTLIT_PI_CLIENT: string;
|
|
10
|
+
/**
|
|
11
|
+
* What the extension registers with no options: Core's default customer intelligence tools, plus the
|
|
12
|
+
* two read-only toolset tools, so an agent that needs a tool outside this list can find out which
|
|
13
|
+
* toolset holds it and tell the user to enable it (the `toolsets` option below). Pi registers tools
|
|
14
|
+
* when the session starts, so loading a toolset never adds callable tools mid-session.
|
|
15
|
+
*/
|
|
16
|
+
declare const piDefaultToolNames: readonly PiToolName[];
|
|
8
17
|
type OutlitPiExtensionOptions = {
|
|
9
18
|
apiKey?: string;
|
|
10
19
|
baseUrl?: string;
|
|
@@ -17,9 +26,27 @@ type OutlitPiExtensionOptions = {
|
|
|
17
26
|
toolsets?: readonly ToolsetName[];
|
|
18
27
|
};
|
|
19
28
|
type OutlitPiRegistry = Pick<ExtensionAPI, "registerTool">;
|
|
29
|
+
/**
|
|
30
|
+
* What a failed call hands the agent: the gateway's whole error envelope (`code`, `message`,
|
|
31
|
+
* `retryable`, `requestId`, and when present `next`, `missingPermission`, `validationIssues`,
|
|
32
|
+
* `retryAfterSeconds`), plus the HTTP `status` when there was a response. A failure with no envelope
|
|
33
|
+
* (a proxy's HTML error page, a dropped connection) carries a `message` and `retryable` only.
|
|
34
|
+
*/
|
|
35
|
+
type OutlitPiToolError = Partial<ToolGatewayErrorEnvelope> & {
|
|
36
|
+
message: string;
|
|
37
|
+
retryable: boolean;
|
|
38
|
+
status?: number;
|
|
39
|
+
};
|
|
20
40
|
type OutlitPiToolDetails = {
|
|
21
41
|
toolName: PiToolName;
|
|
42
|
+
/** The tool's result; `{ error }` when the call failed (see `error`). */
|
|
22
43
|
result: unknown;
|
|
44
|
+
/** Set when the call failed at the gateway or the network; the agent sees it as the tool result. */
|
|
45
|
+
error?: OutlitPiToolError;
|
|
46
|
+
/** Core's `outlit-request-id` for this call, success or failure: quote it when reporting a problem. */
|
|
47
|
+
requestId?: string;
|
|
48
|
+
/** Core's `outlit-version`: the dated output version that answered. */
|
|
49
|
+
version?: string;
|
|
23
50
|
};
|
|
24
51
|
type OutlitPiToolDefinition = ToolDefinition<TSchema, OutlitPiToolDetails>;
|
|
25
52
|
declare function createOutlitPiExtension(options?: OutlitPiExtensionOptions): (pi: OutlitPiRegistry) => void;
|
|
@@ -32,4 +59,4 @@ type PublicToolName = PiToolName;
|
|
|
32
59
|
|
|
33
60
|
declare const _default: (pi: OutlitPiRegistry) => void;
|
|
34
61
|
|
|
35
|
-
export { OUTLIT_API_KEY_ENV, OUTLIT_API_URL_ENV, type OutlitPiExtensionOptions, type OutlitPiRegistry, type OutlitPiToolDefinition, type OutlitPiToolDetails, type PublicToolName, createOutlitPiExtension, createOutlitPiTool, createOutlitPiTools, _default as default, formatOutlitToolLabel };
|
|
62
|
+
export { OUTLIT_API_KEY_ENV, OUTLIT_API_URL_ENV, OUTLIT_PI_CLIENT, type OutlitPiExtensionOptions, type OutlitPiRegistry, type OutlitPiToolDefinition, type OutlitPiToolDetails, type OutlitPiToolError, type PublicToolName, createOutlitPiExtension, createOutlitPiTool, createOutlitPiTools, _default as default, formatOutlitToolLabel, piDefaultToolNames };
|
package/dist/index.js
CHANGED
|
@@ -4,10 +4,98 @@ import {
|
|
|
4
4
|
DEFAULT_OUTLIT_API_URL,
|
|
5
5
|
defaultToolNames,
|
|
6
6
|
getPublicToolContract,
|
|
7
|
+
isOutlitToolsApiError,
|
|
7
8
|
isPublicToolName,
|
|
8
9
|
piToolNames,
|
|
9
10
|
toolNamesInToolsets
|
|
10
11
|
} from "@outlit/tools";
|
|
12
|
+
|
|
13
|
+
// package.json
|
|
14
|
+
var package_default = {
|
|
15
|
+
name: "@outlit/pi",
|
|
16
|
+
version: "4.0.0",
|
|
17
|
+
description: "Pi package for Outlit customer intelligence tools and skill guidance",
|
|
18
|
+
license: "Apache-2.0",
|
|
19
|
+
author: "Outlit AI",
|
|
20
|
+
repository: {
|
|
21
|
+
type: "git",
|
|
22
|
+
url: "https://github.com/OutlitAI/outlit-sdk.git",
|
|
23
|
+
directory: "packages/pi"
|
|
24
|
+
},
|
|
25
|
+
bugs: {
|
|
26
|
+
url: "https://github.com/OutlitAI/outlit-sdk/issues"
|
|
27
|
+
},
|
|
28
|
+
homepage: "https://docs.outlit.ai/ai-integrations/pi",
|
|
29
|
+
keywords: [
|
|
30
|
+
"outlit",
|
|
31
|
+
"pi",
|
|
32
|
+
"pi-package",
|
|
33
|
+
"agents",
|
|
34
|
+
"ai-agents",
|
|
35
|
+
"mcp",
|
|
36
|
+
"customer-intelligence"
|
|
37
|
+
],
|
|
38
|
+
pi: {
|
|
39
|
+
extensions: [
|
|
40
|
+
"./dist/extension.js"
|
|
41
|
+
],
|
|
42
|
+
skills: [
|
|
43
|
+
"./skills"
|
|
44
|
+
]
|
|
45
|
+
},
|
|
46
|
+
publishConfig: {
|
|
47
|
+
access: "public"
|
|
48
|
+
},
|
|
49
|
+
type: "module",
|
|
50
|
+
main: "./dist/index.cjs",
|
|
51
|
+
module: "./dist/index.js",
|
|
52
|
+
types: "./dist/index.d.ts",
|
|
53
|
+
exports: {
|
|
54
|
+
".": {
|
|
55
|
+
types: "./dist/index.d.ts",
|
|
56
|
+
import: "./dist/index.js",
|
|
57
|
+
require: "./dist/index.cjs",
|
|
58
|
+
default: "./dist/index.js"
|
|
59
|
+
},
|
|
60
|
+
"./extension": {
|
|
61
|
+
types: "./dist/extension.d.ts",
|
|
62
|
+
import: "./dist/extension.js",
|
|
63
|
+
require: "./dist/extension.cjs",
|
|
64
|
+
default: "./dist/extension.js"
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
files: [
|
|
68
|
+
"dist",
|
|
69
|
+
"skills",
|
|
70
|
+
"README.md"
|
|
71
|
+
],
|
|
72
|
+
scripts: {
|
|
73
|
+
build: "tsup",
|
|
74
|
+
dev: "tsup --watch",
|
|
75
|
+
clean: "rm -rf dist .turbo node_modules",
|
|
76
|
+
lint: "biome check . --write",
|
|
77
|
+
format: "biome format --write .",
|
|
78
|
+
typecheck: "tsc --noEmit",
|
|
79
|
+
test: "vitest run"
|
|
80
|
+
},
|
|
81
|
+
dependencies: {
|
|
82
|
+
"@outlit/tools": "^4.0.0"
|
|
83
|
+
},
|
|
84
|
+
peerDependencies: {
|
|
85
|
+
"@mariozechner/pi-coding-agent": "*",
|
|
86
|
+
"@sinclair/typebox": "*"
|
|
87
|
+
},
|
|
88
|
+
devDependencies: {
|
|
89
|
+
"@mariozechner/pi-coding-agent": "^0.67.1",
|
|
90
|
+
"@outlit/typescript-config": "workspace:*",
|
|
91
|
+
"@sinclair/typebox": "^0.34.41",
|
|
92
|
+
tsup: "^8.5.1",
|
|
93
|
+
typescript: "^5.9.3",
|
|
94
|
+
vitest: "^4.0.18"
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
// src/index.ts
|
|
11
99
|
import {
|
|
12
100
|
analyticalToolNames,
|
|
13
101
|
defaultToolNames as defaultToolNames2,
|
|
@@ -18,7 +106,13 @@ import {
|
|
|
18
106
|
} from "@outlit/tools";
|
|
19
107
|
var OUTLIT_API_KEY_ENV = "OUTLIT_API_KEY";
|
|
20
108
|
var OUTLIT_API_URL_ENV = "OUTLIT_API_URL";
|
|
109
|
+
var OUTLIT_PI_CLIENT = `@outlit/pi/${package_default.version}`;
|
|
21
110
|
var piToolNameSet = new Set(piToolNames);
|
|
111
|
+
var piDefaultToolNames = [
|
|
112
|
+
...defaultToolNames,
|
|
113
|
+
"outlit_list_toolsets",
|
|
114
|
+
"outlit_load_toolset"
|
|
115
|
+
];
|
|
22
116
|
function createOutlitPiExtension(options = {}) {
|
|
23
117
|
return function outlitPiExtension(pi) {
|
|
24
118
|
for (const tool of createOutlitPiTools(options)) {
|
|
@@ -50,12 +144,23 @@ function createOutlitPiTool(toolName, options = {}) {
|
|
|
50
144
|
apiKey: resolveApiKey(options),
|
|
51
145
|
baseUrl: resolveBaseUrl(options),
|
|
52
146
|
fetch: options.fetch,
|
|
147
|
+
client: OUTLIT_PI_CLIENT,
|
|
53
148
|
onResponse: (info) => {
|
|
54
149
|
responseInfo = info;
|
|
55
150
|
}
|
|
56
151
|
});
|
|
57
|
-
const
|
|
58
|
-
|
|
152
|
+
const input = normalizeToolInput(params);
|
|
153
|
+
try {
|
|
154
|
+
const result = await client.callTool(toolName, input);
|
|
155
|
+
return formatToolResult(toolName, result, responseInfo);
|
|
156
|
+
} catch (error) {
|
|
157
|
+
return formatToolError(
|
|
158
|
+
toolName,
|
|
159
|
+
toToolError(error, responseInfo),
|
|
160
|
+
responseNotices(responseInfo),
|
|
161
|
+
responseInfo
|
|
162
|
+
);
|
|
163
|
+
}
|
|
59
164
|
}
|
|
60
165
|
};
|
|
61
166
|
}
|
|
@@ -71,7 +176,7 @@ function formatOutlitToolLabel(toolName) {
|
|
|
71
176
|
}
|
|
72
177
|
function resolveToolNames(options) {
|
|
73
178
|
const names = [
|
|
74
|
-
...options.toolNames ?? (options.toolsets ? [] :
|
|
179
|
+
...options.toolNames ?? (options.toolsets ? [] : piDefaultToolNames),
|
|
75
180
|
...options.toolsets ? toolNamesInToolsets(options.toolsets) : []
|
|
76
181
|
];
|
|
77
182
|
return [...new Set(names)].map((name) => {
|
|
@@ -111,6 +216,35 @@ function responseNotices(info) {
|
|
|
111
216
|
...info.notices
|
|
112
217
|
];
|
|
113
218
|
}
|
|
219
|
+
function toToolError(error, info) {
|
|
220
|
+
if (isOutlitToolsApiError(error)) {
|
|
221
|
+
if (error.envelope) return { ...error.envelope, status: error.status };
|
|
222
|
+
return {
|
|
223
|
+
message: error.message,
|
|
224
|
+
retryable: error.status === 429 || error.status >= 500,
|
|
225
|
+
status: error.status,
|
|
226
|
+
...error.requestId ?? info?.requestId ? { requestId: error.requestId ?? info?.requestId } : {}
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
return { message: error instanceof Error ? error.message : String(error), retryable: true };
|
|
230
|
+
}
|
|
231
|
+
function formatToolError(toolName, error, notices, info) {
|
|
232
|
+
const result = { error };
|
|
233
|
+
return {
|
|
234
|
+
content: [
|
|
235
|
+
{ type: "text", text: JSON.stringify(result, null, 2) },
|
|
236
|
+
...notices.length > 0 ? [{ type: "text", text: `Notice: ${notices.join(" ")}` }] : []
|
|
237
|
+
],
|
|
238
|
+
details: { toolName, result, error, ...responseIds(info, error.requestId) }
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
function responseIds(info, fallbackRequestId) {
|
|
242
|
+
const requestId = info?.requestId ?? fallbackRequestId;
|
|
243
|
+
return {
|
|
244
|
+
...requestId ? { requestId } : {},
|
|
245
|
+
...info?.version ? { version: info.version } : {}
|
|
246
|
+
};
|
|
247
|
+
}
|
|
114
248
|
function formatToolResult(toolName, result, info) {
|
|
115
249
|
const notices = responseNotices(info);
|
|
116
250
|
return {
|
|
@@ -121,7 +255,8 @@ function formatToolResult(toolName, result, info) {
|
|
|
121
255
|
],
|
|
122
256
|
details: {
|
|
123
257
|
toolName,
|
|
124
|
-
result
|
|
258
|
+
result,
|
|
259
|
+
...responseIds(info)
|
|
125
260
|
}
|
|
126
261
|
};
|
|
127
262
|
}
|
|
@@ -132,6 +267,7 @@ var src_default = createOutlitPiExtension();
|
|
|
132
267
|
export {
|
|
133
268
|
OUTLIT_API_KEY_ENV,
|
|
134
269
|
OUTLIT_API_URL_ENV,
|
|
270
|
+
OUTLIT_PI_CLIENT,
|
|
135
271
|
piToolNames3 as allPublicToolNames,
|
|
136
272
|
analyticalToolNames,
|
|
137
273
|
createOutlitPiExtension,
|
|
@@ -140,6 +276,7 @@ export {
|
|
|
140
276
|
src_default as default,
|
|
141
277
|
defaultToolNames2 as defaultToolNames,
|
|
142
278
|
formatOutlitToolLabel,
|
|
279
|
+
piDefaultToolNames,
|
|
143
280
|
piToolNames2 as piToolNames,
|
|
144
281
|
sqlToolNames,
|
|
145
282
|
toolsetNames
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { AgentToolResult, ExtensionAPI, ToolDefinition } from \"@mariozechner/pi-coding-agent\"\nimport {\n createOutlitClient,\n DEFAULT_OUTLIT_API_URL,\n defaultToolNames,\n getPublicToolContract,\n isPublicToolName,\n type OutlitToolsFetch,\n type OutlitToolsResponseInfo,\n type PiToolName,\n piToolNames,\n type ToolsetName,\n toolNamesInToolsets,\n} from \"@outlit/tools\"\nimport type { TSchema } from \"@sinclair/typebox\"\n\nexport const OUTLIT_API_KEY_ENV = \"OUTLIT_API_KEY\"\nexport const OUTLIT_API_URL_ENV = \"OUTLIT_API_URL\"\n\nconst piToolNameSet = new Set<string>(piToolNames)\n\nexport type OutlitPiExtensionOptions = {\n apiKey?: string\n baseUrl?: string\n fetch?: OutlitToolsFetch\n toolNames?: readonly PiToolName[]\n /**\n * Register every tool in these Core toolsets (core, work, identity, admin, meta). With `toolNames`\n * too, both apply; with neither, the default read-only tools are registered.\n */\n toolsets?: readonly ToolsetName[]\n}\n\nexport type OutlitPiRegistry = Pick<ExtensionAPI, \"registerTool\">\n\nexport type OutlitPiToolDetails = {\n toolName: PiToolName\n result: unknown\n}\n\nexport type OutlitPiToolDefinition = ToolDefinition<TSchema, OutlitPiToolDetails>\n\nexport function createOutlitPiExtension(options: OutlitPiExtensionOptions = {}) {\n return function outlitPiExtension(pi: OutlitPiRegistry) {\n for (const tool of createOutlitPiTools(options)) {\n pi.registerTool(tool)\n }\n }\n}\n\nexport function createOutlitPiTools(\n options: OutlitPiExtensionOptions = {},\n): OutlitPiToolDefinition[] {\n return resolveToolNames(options).map((toolName) => createOutlitPiTool(toolName, options))\n}\n\nexport function createOutlitPiTool(\n toolName: PiToolName,\n options: OutlitPiExtensionOptions = {},\n): OutlitPiToolDefinition {\n if (!isPublicToolName(toolName)) {\n throw new Error(`Unknown Outlit public tool: ${toolName}`)\n }\n if (!piToolNameSet.has(toolName)) {\n throw new Error(`Tool is not available in @outlit/pi: ${toolName}`)\n }\n\n const contract = getPublicToolContract(toolName)\n const label = formatOutlitToolLabel(toolName)\n\n return {\n name: toolName,\n label,\n description: contract.description,\n promptSnippet: `${label}: ${firstLine(contract.description)}`,\n parameters: toPiToolParameters(contract.inputSchema),\n async execute(_toolCallId, params) {\n let responseInfo: OutlitToolsResponseInfo | undefined\n const client = createOutlitClient({\n apiKey: resolveApiKey(options),\n baseUrl: resolveBaseUrl(options),\n fetch: options.fetch,\n onResponse: (info) => {\n responseInfo = info\n },\n })\n const result = await client.callTool(toolName, normalizeToolInput(params))\n\n return formatToolResult(toolName, result, responseInfo)\n },\n }\n}\n\nfunction toPiToolParameters(inputSchema: unknown): TSchema {\n if (inputSchema === null || typeof inputSchema !== \"object\" || Array.isArray(inputSchema)) {\n return inputSchema as TSchema\n }\n\n const { $schema: _schema, ...schema } = inputSchema as Record<string, unknown>\n return schema as unknown as TSchema\n}\n\nexport function formatOutlitToolLabel(toolName: PiToolName): string {\n return toolName\n .split(\"_\")\n .map((part) => part.charAt(0).toUpperCase() + part.slice(1))\n .join(\" \")\n}\n\nfunction resolveToolNames(options: OutlitPiExtensionOptions): PiToolName[] {\n const names: readonly string[] = [\n ...(options.toolNames ?? (options.toolsets ? [] : defaultToolNames)),\n ...(options.toolsets ? toolNamesInToolsets(options.toolsets) : []),\n ]\n\n return [...new Set(names)].map((name) => {\n if (!isPublicToolName(name)) {\n throw new Error(`Unknown Outlit public tool: ${name}`)\n }\n\n return name as PiToolName\n })\n}\n\nfunction resolveApiKey(options: OutlitPiExtensionOptions): string {\n const apiKey = normalizeString(options.apiKey) ?? normalizeString(process.env[OUTLIT_API_KEY_ENV])\n\n if (!apiKey) {\n throw new Error(`${OUTLIT_API_KEY_ENV} is required to use @outlit/pi tools`)\n }\n\n return apiKey\n}\n\nfunction resolveBaseUrl(options: OutlitPiExtensionOptions): string {\n return (\n normalizeString(options.baseUrl) ??\n normalizeString(process.env[OUTLIT_API_URL_ENV]) ??\n DEFAULT_OUTLIT_API_URL\n )\n}\n\nfunction normalizeString(value: string | undefined): string | undefined {\n const trimmed = value?.trim()\n return trimmed ? trimmed : undefined\n}\n\nfunction normalizeToolInput(params: unknown): Record<string, unknown> {\n if (params === undefined) {\n return {}\n }\n\n if (params === null || typeof params !== \"object\" || Array.isArray(params)) {\n throw new TypeError(\"Outlit Pi tool input must be an object\")\n }\n\n return params as Record<string, unknown>\n}\n\n/** What the gateway said beside the result, as sentences for the agent: a deprecation, then notices. */\nfunction responseNotices(info: OutlitToolsResponseInfo | undefined): string[] {\n if (!info) return []\n return [\n ...(info.deprecation ? [`${info.deprecation.message} (until ${info.deprecation.until})`] : []),\n ...info.notices,\n ]\n}\n\nfunction formatToolResult(\n toolName: PiToolName,\n result: unknown,\n info?: OutlitToolsResponseInfo,\n): AgentToolResult<OutlitPiToolDetails> {\n const notices = responseNotices(info)\n return {\n content: [\n { type: \"text\", text: JSON.stringify(result, null, 2) ?? String(result) },\n // After the result, so a reader of the first block still gets the JSON alone.\n ...(notices.length > 0\n ? [{ type: \"text\" as const, text: `Notice: ${notices.join(\" \")}` }]\n : []),\n ],\n details: {\n toolName,\n result,\n },\n }\n}\n\nfunction firstLine(value: string): string {\n return value.split(\"\\n\", 1)[0] ?? value\n}\n\nexport type { PiToolName } from \"@outlit/tools\"\n/** @deprecated Use PiToolName. */\nexport type PublicToolName = PiToolName\nexport type { ToolsetName } from \"@outlit/tools\"\nexport {\n analyticalToolNames,\n defaultToolNames,\n piToolNames,\n piToolNames as allPublicToolNames,\n sqlToolNames,\n toolsetNames,\n} from \"@outlit/tools\"\n\nexport default createOutlitPiExtension()\n"],"mappings":";AACA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAIA;AAAA,EAEA;AAAA,OACK;AAwLP;AAAA,EACE;AAAA,EACA,oBAAAA;AAAA,EACA,eAAAC;AAAA,EACe,eAAfA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AA5LA,IAAM,qBAAqB;AAC3B,IAAM,qBAAqB;AAElC,IAAM,gBAAgB,IAAI,IAAY,WAAW;AAuB1C,SAAS,wBAAwB,UAAoC,CAAC,GAAG;AAC9E,SAAO,SAAS,kBAAkB,IAAsB;AACtD,eAAW,QAAQ,oBAAoB,OAAO,GAAG;AAC/C,SAAG,aAAa,IAAI;AAAA,IACtB;AAAA,EACF;AACF;AAEO,SAAS,oBACd,UAAoC,CAAC,GACX;AAC1B,SAAO,iBAAiB,OAAO,EAAE,IAAI,CAAC,aAAa,mBAAmB,UAAU,OAAO,CAAC;AAC1F;AAEO,S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,UAAU,gBAAgB,IAAI;AACpC,SAAO;AAAA,IACL,SAAS;AAAA,MACP,EAAE,MAAM,QAAQ,MAAM,KAAK,UAAU,QAAQ,MAAM,CAAC,KAAK,OAAO,MAAM,EAAE;AAAA;AAAA,MAExE,GAAI,QAAQ,SAAS,IACjB,CAAC,EAAE,MAAM,QAAiB,MAAM,WAAW,QAAQ,KAAK,GAAG,CAAC,GAAG,CAAC,IAChE,CAAC;AAAA,IACP;AAAA,IACA,SAAS;AAAA,MACP;AAAA,MACA;AAAA,IACF;AAAA,EACF;AACF;AAEA,SAAS,UAAU,OAAuB;AACxC,SAAO,MAAM,MAAM,MAAM,CAAC,EAAE,CAAC,KAAK;AACpC;AAeA,IAAO,cAAQ,wBAAwB;","names":["defaultToolNames","piToolNames"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../package.json"],"sourcesContent":["import type { AgentToolResult, ExtensionAPI, ToolDefinition } from \"@mariozechner/pi-coding-agent\"\nimport {\n createOutlitClient,\n DEFAULT_OUTLIT_API_URL,\n defaultToolNames,\n getPublicToolContract,\n isOutlitToolsApiError,\n isPublicToolName,\n type OutlitToolsFetch,\n type OutlitToolsResponseInfo,\n type PiToolName,\n piToolNames,\n type ToolGatewayErrorEnvelope,\n type ToolsetName,\n toolNamesInToolsets,\n} from \"@outlit/tools\"\nimport type { TSchema } from \"@sinclair/typebox\"\nimport pkg from \"../package.json\" with { type: \"json\" }\n\nexport const OUTLIT_API_KEY_ENV = \"OUTLIT_API_KEY\"\nexport const OUTLIT_API_URL_ENV = \"OUTLIT_API_URL\"\n\n/** Sent as `x-outlit-client`, so Core can tell a Pi extension below a release's minimum version. */\nexport const OUTLIT_PI_CLIENT = `@outlit/pi/${pkg.version}`\n\nconst piToolNameSet = new Set<string>(piToolNames)\n\n/**\n * What the extension registers with no options: Core's default customer intelligence tools, plus the\n * two read-only toolset tools, so an agent that needs a tool outside this list can find out which\n * toolset holds it and tell the user to enable it (the `toolsets` option below). Pi registers tools\n * when the session starts, so loading a toolset never adds callable tools mid-session.\n */\nexport const piDefaultToolNames: readonly PiToolName[] = [\n ...defaultToolNames,\n \"outlit_list_toolsets\",\n \"outlit_load_toolset\",\n]\n\nexport type OutlitPiExtensionOptions = {\n apiKey?: string\n baseUrl?: string\n fetch?: OutlitToolsFetch\n toolNames?: readonly PiToolName[]\n /**\n * Register every tool in these Core toolsets (core, work, identity, admin, meta). With `toolNames`\n * too, both apply; with neither, the default read-only tools are registered.\n */\n toolsets?: readonly ToolsetName[]\n}\n\nexport type OutlitPiRegistry = Pick<ExtensionAPI, \"registerTool\">\n\n/**\n * What a failed call hands the agent: the gateway's whole error envelope (`code`, `message`,\n * `retryable`, `requestId`, and when present `next`, `missingPermission`, `validationIssues`,\n * `retryAfterSeconds`), plus the HTTP `status` when there was a response. A failure with no envelope\n * (a proxy's HTML error page, a dropped connection) carries a `message` and `retryable` only.\n */\nexport type OutlitPiToolError = Partial<ToolGatewayErrorEnvelope> & {\n message: string\n retryable: boolean\n status?: number\n}\n\nexport type OutlitPiToolDetails = {\n toolName: PiToolName\n /** The tool's result; `{ error }` when the call failed (see `error`). */\n result: unknown\n /** Set when the call failed at the gateway or the network; the agent sees it as the tool result. */\n error?: OutlitPiToolError\n /** Core's `outlit-request-id` for this call, success or failure: quote it when reporting a problem. */\n requestId?: string\n /** Core's `outlit-version`: the dated output version that answered. */\n version?: string\n}\n\nexport type OutlitPiToolDefinition = ToolDefinition<TSchema, OutlitPiToolDetails>\n\nexport function createOutlitPiExtension(options: OutlitPiExtensionOptions = {}) {\n return function outlitPiExtension(pi: OutlitPiRegistry) {\n for (const tool of createOutlitPiTools(options)) {\n pi.registerTool(tool)\n }\n }\n}\n\nexport function createOutlitPiTools(\n options: OutlitPiExtensionOptions = {},\n): OutlitPiToolDefinition[] {\n return resolveToolNames(options).map((toolName) => createOutlitPiTool(toolName, options))\n}\n\nexport function createOutlitPiTool(\n toolName: PiToolName,\n options: OutlitPiExtensionOptions = {},\n): OutlitPiToolDefinition {\n if (!isPublicToolName(toolName)) {\n throw new Error(`Unknown Outlit public tool: ${toolName}`)\n }\n if (!piToolNameSet.has(toolName)) {\n throw new Error(`Tool is not available in @outlit/pi: ${toolName}`)\n }\n\n const contract = getPublicToolContract(toolName)\n const label = formatOutlitToolLabel(toolName)\n\n return {\n name: toolName,\n label,\n description: contract.description,\n promptSnippet: `${label}: ${firstLine(contract.description)}`,\n parameters: toPiToolParameters(contract.inputSchema),\n async execute(_toolCallId, params) {\n let responseInfo: OutlitToolsResponseInfo | undefined\n const client = createOutlitClient({\n apiKey: resolveApiKey(options),\n baseUrl: resolveBaseUrl(options),\n fetch: options.fetch,\n client: OUTLIT_PI_CLIENT,\n onResponse: (info) => {\n responseInfo = info\n },\n })\n const input = normalizeToolInput(params)\n try {\n const result = await client.callTool(toolName, input)\n return formatToolResult(toolName, result, responseInfo)\n } catch (error) {\n // A failed call is something the agent can act on, not a crash: hand it the envelope.\n return formatToolError(\n toolName,\n toToolError(error, responseInfo),\n responseNotices(responseInfo),\n responseInfo,\n )\n }\n },\n }\n}\n\nfunction toPiToolParameters(inputSchema: unknown): TSchema {\n if (inputSchema === null || typeof inputSchema !== \"object\" || Array.isArray(inputSchema)) {\n return inputSchema as TSchema\n }\n\n const { $schema: _schema, ...schema } = inputSchema as Record<string, unknown>\n return schema as unknown as TSchema\n}\n\nexport function formatOutlitToolLabel(toolName: PiToolName): string {\n return toolName\n .split(\"_\")\n .map((part) => part.charAt(0).toUpperCase() + part.slice(1))\n .join(\" \")\n}\n\nfunction resolveToolNames(options: OutlitPiExtensionOptions): PiToolName[] {\n const names: readonly string[] = [\n ...(options.toolNames ?? (options.toolsets ? [] : piDefaultToolNames)),\n ...(options.toolsets ? toolNamesInToolsets(options.toolsets) : []),\n ]\n\n return [...new Set(names)].map((name) => {\n if (!isPublicToolName(name)) {\n throw new Error(`Unknown Outlit public tool: ${name}`)\n }\n\n return name as PiToolName\n })\n}\n\nfunction resolveApiKey(options: OutlitPiExtensionOptions): string {\n const apiKey = normalizeString(options.apiKey) ?? normalizeString(process.env[OUTLIT_API_KEY_ENV])\n\n if (!apiKey) {\n throw new Error(`${OUTLIT_API_KEY_ENV} is required to use @outlit/pi tools`)\n }\n\n return apiKey\n}\n\nfunction resolveBaseUrl(options: OutlitPiExtensionOptions): string {\n return (\n normalizeString(options.baseUrl) ??\n normalizeString(process.env[OUTLIT_API_URL_ENV]) ??\n DEFAULT_OUTLIT_API_URL\n )\n}\n\nfunction normalizeString(value: string | undefined): string | undefined {\n const trimmed = value?.trim()\n return trimmed ? trimmed : undefined\n}\n\nfunction normalizeToolInput(params: unknown): Record<string, unknown> {\n if (params === undefined) {\n return {}\n }\n\n if (params === null || typeof params !== \"object\" || Array.isArray(params)) {\n throw new TypeError(\"Outlit Pi tool input must be an object\")\n }\n\n return params as Record<string, unknown>\n}\n\n/** What the gateway said beside the result, as sentences for the agent: a deprecation, then notices. */\nfunction responseNotices(info: OutlitToolsResponseInfo | undefined): string[] {\n if (!info) return []\n return [\n ...(info.deprecation ? [`${info.deprecation.message} (until ${info.deprecation.until})`] : []),\n ...info.notices,\n ]\n}\n\nfunction toToolError(error: unknown, info?: OutlitToolsResponseInfo): OutlitPiToolError {\n if (isOutlitToolsApiError(error)) {\n if (error.envelope) return { ...error.envelope, status: error.status }\n return {\n message: error.message,\n retryable: error.status === 429 || error.status >= 500,\n status: error.status,\n ...((error.requestId ?? info?.requestId)\n ? { requestId: error.requestId ?? info?.requestId }\n : {}),\n }\n }\n // fetch rejecting (offline, DNS, reset) or a 200 whose body was not JSON.\n return { message: error instanceof Error ? error.message : String(error), retryable: true }\n}\n\nfunction formatToolError(\n toolName: PiToolName,\n error: OutlitPiToolError,\n notices: string[],\n info?: OutlitToolsResponseInfo,\n): AgentToolResult<OutlitPiToolDetails> {\n const result = { error }\n return {\n content: [\n { type: \"text\", text: JSON.stringify(result, null, 2) },\n ...(notices.length > 0\n ? [{ type: \"text\" as const, text: `Notice: ${notices.join(\" \")}` }]\n : []),\n ],\n details: { toolName, result, error, ...responseIds(info, error.requestId) },\n }\n}\n\nfunction responseIds(\n info: OutlitToolsResponseInfo | undefined,\n fallbackRequestId?: string,\n): { requestId?: string; version?: string } {\n const requestId = info?.requestId ?? fallbackRequestId\n return {\n ...(requestId ? { requestId } : {}),\n ...(info?.version ? { version: info.version } : {}),\n }\n}\n\nfunction formatToolResult(\n toolName: PiToolName,\n result: unknown,\n info?: OutlitToolsResponseInfo,\n): AgentToolResult<OutlitPiToolDetails> {\n const notices = responseNotices(info)\n return {\n content: [\n { type: \"text\", text: JSON.stringify(result, null, 2) ?? String(result) },\n // After the result, so a reader of the first block still gets the JSON alone.\n ...(notices.length > 0\n ? [{ type: \"text\" as const, text: `Notice: ${notices.join(\" \")}` }]\n : []),\n ],\n details: {\n toolName,\n result,\n ...responseIds(info),\n },\n }\n}\n\nfunction firstLine(value: string): string {\n return value.split(\"\\n\", 1)[0] ?? value\n}\n\nexport type { PiToolName } from \"@outlit/tools\"\n/** @deprecated Use PiToolName. */\nexport type PublicToolName = PiToolName\nexport type { ToolsetName } from \"@outlit/tools\"\nexport {\n analyticalToolNames,\n defaultToolNames,\n piToolNames,\n piToolNames as allPublicToolNames,\n sqlToolNames,\n toolsetNames,\n} from \"@outlit/tools\"\n\nexport default createOutlitPiExtension()\n","{\n \"name\": \"@outlit/pi\",\n \"version\": \"4.0.0\",\n \"description\": \"Pi package for Outlit customer intelligence tools and skill guidance\",\n \"license\": \"Apache-2.0\",\n \"author\": \"Outlit AI\",\n \"repository\": {\n \"type\": \"git\",\n \"url\": \"https://github.com/OutlitAI/outlit-sdk.git\",\n \"directory\": \"packages/pi\"\n },\n \"bugs\": {\n \"url\": \"https://github.com/OutlitAI/outlit-sdk/issues\"\n },\n \"homepage\": \"https://docs.outlit.ai/ai-integrations/pi\",\n \"keywords\": [\n \"outlit\",\n \"pi\",\n \"pi-package\",\n \"agents\",\n \"ai-agents\",\n \"mcp\",\n \"customer-intelligence\"\n ],\n \"pi\": {\n \"extensions\": [\n \"./dist/extension.js\"\n ],\n \"skills\": [\n \"./skills\"\n ]\n },\n \"publishConfig\": {\n \"access\": \"public\"\n },\n \"type\": \"module\",\n \"main\": \"./dist/index.cjs\",\n \"module\": \"./dist/index.js\",\n \"types\": \"./dist/index.d.ts\",\n \"exports\": {\n \".\": {\n \"types\": \"./dist/index.d.ts\",\n \"import\": \"./dist/index.js\",\n \"require\": \"./dist/index.cjs\",\n \"default\": \"./dist/index.js\"\n },\n \"./extension\": {\n \"types\": \"./dist/extension.d.ts\",\n \"import\": \"./dist/extension.js\",\n \"require\": \"./dist/extension.cjs\",\n \"default\": \"./dist/extension.js\"\n }\n },\n \"files\": [\n \"dist\",\n \"skills\",\n \"README.md\"\n ],\n \"scripts\": {\n \"build\": \"tsup\",\n \"dev\": \"tsup --watch\",\n \"clean\": \"rm -rf dist .turbo node_modules\",\n \"lint\": \"biome check . --write\",\n \"format\": \"biome format --write .\",\n \"typecheck\": \"tsc --noEmit\",\n \"test\": \"vitest run\"\n },\n \"dependencies\": {\n \"@outlit/tools\": \"^4.0.0\"\n },\n \"peerDependencies\": {\n \"@mariozechner/pi-coding-agent\": \"*\",\n \"@sinclair/typebox\": \"*\"\n },\n \"devDependencies\": {\n \"@mariozechner/pi-coding-agent\": \"^0.67.1\",\n \"@outlit/typescript-config\": \"workspace:*\",\n \"@sinclair/typebox\": \"^0.34.41\",\n \"tsup\": \"^8.5.1\",\n \"typescript\": \"^5.9.3\",\n \"vitest\": \"^4.0.18\"\n }\n}\n"],"mappings":";AACA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAIA;AAAA,EAGA;AAAA,OACK;;;ACfP;AAAA,EACE,MAAQ;AAAA,EACR,SAAW;AAAA,EACX,aAAe;AAAA,EACf,SAAW;AAAA,EACX,QAAU;AAAA,EACV,YAAc;AAAA,IACZ,MAAQ;AAAA,IACR,KAAO;AAAA,IACP,WAAa;AAAA,EACf;AAAA,EACA,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IACjB,CAAC,EAAE,MAAM,QAAiB,MAAM,WAAW,QAAQ,KAAK,GAAG,CAAC,GAAG,CAAC,IAChE,CAAC;AAAA,IACP;AAAA,IACA,SAAS,EAAE,UAAU,QAAQ,OAAO,GAAG,YAAY,MAAM,MAAM,SAAS,EAAE;AAAA,EAC5E;AACF;AAEA,SAAS,YACP,MACA,mBAC0C;AAC1C,QAAM,YAAY,MAAM,aAAa;AACrC,SAAO;AAAA,IACL,GAAI,YAAY,EAAE,UAAU,IAAI,CAAC;AAAA,IACjC,GAAI,MAAM,UAAU,EAAE,SAAS,KAAK,QAAQ,IAAI,CAAC;AAAA,EACnD;AACF;AAEA,SAAS,iBACP,UACA,QACA,MACsC;AACtC,QAAM,UAAU,gBAAgB,IAAI;AACpC,SAAO;AAAA,IACL,SAAS;AAAA,MACP,EAAE,MAAM,QAAQ,MAAM,KAAK,UAAU,QAAQ,MAAM,CAAC,KAAK,OAAO,MAAM,EAAE;AAAA;AAAA,MAExE,GAAI,QAAQ,SAAS,IACjB,CAAC,EAAE,MAAM,QAAiB,MAAM,WAAW,QAAQ,KAAK,GAAG,CAAC,GAAG,CAAC,IAChE,CAAC;AAAA,IACP;AAAA,IACA,SAAS;AAAA,MACP;AAAA,MACA;AAAA,MACA,GAAG,YAAY,IAAI;AAAA,IACrB;AAAA,EACF;AACF;AAEA,SAAS,UAAU,OAAuB;AACxC,SAAO,MAAM,MAAM,MAAM,CAAC,EAAE,CAAC,KAAK;AACpC;AAeA,IAAO,cAAQ,wBAAwB;","names":["defaultToolNames","piToolNames"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@outlit/pi",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"description": "Pi package for Outlit customer intelligence tools and skill guidance",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "Outlit AI",
|
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
"test": "vitest run"
|
|
67
67
|
},
|
|
68
68
|
"dependencies": {
|
|
69
|
-
"@outlit/tools": "^
|
|
69
|
+
"@outlit/tools": "^4.0.0"
|
|
70
70
|
},
|
|
71
71
|
"peerDependencies": {
|
|
72
72
|
"@mariozechner/pi-coding-agent": "*",
|
package/skills/outlit/SKILL.md
CHANGED
|
@@ -20,8 +20,8 @@ Do not invent customer state when Outlit can answer it. Call out sparse or messy
|
|
|
20
20
|
Each included section reports a `status`: only `available` has `data`; `empty`, `not_connected`, `not_synced` and `unavailable` say why there is none, which is not the same as zero. Money values carry `formatted` text; show it as is.
|
|
21
21
|
Ask for what the answer needs with `include`: `relationship` (a summary and up to eight current statements), `features` (product-event features), `meters` (Autumn metered quantities) and `credits` (credit pools with balance and burn rate). `hierarchy` is the parent company and direct subsidiaries the CRM records. `features`, `meters`, `credits` and `hierarchy`'s children come in pages of 25; page one with its own `limit` and `cursor`.
|
|
22
22
|
- Use `outlit_get_timeline` when order, recency, activity sequence, meetings, messages, product usage, support, or billing chronology matters. Filters live under `filters`: `channels` (lowercase, such as `communication` or `product`), `eventTypes`, and a window as `within` or `after` with an optional `before`. Page with `page.nextCursor`.
|
|
23
|
-
- Use `outlit_list_facts` to browse structured account facts, known signals, open issues, health indicators, relationship notes, activation, billing, or renewal context. Narrow with `filters.status`, `filters.sourceTypes`, `filters.types`, and `filters.categories` when you know what evidence class you need; all values are lowercase.
|
|
24
|
-
- Use `outlit_get_fact` when you already have a fact id and need the
|
|
23
|
+
- Use `outlit_list_facts` to browse structured account facts, known signals, open issues, health indicators, relationship notes, activation, billing, or renewal context. Narrow with `filters.status`, `filters.sourceTypes`, `filters.types`, and `filters.categories` when you know what evidence class you need; all values are lowercase. A listed fact is concise: it has no `reasoning` or `source.quote` unless you ask with `include` (`reasoning`, `quote`, `evidence`), and `evidence` then holds only the first three cited excerpts as `{ items, page, more }`.
|
|
24
|
+
- Use `outlit_get_fact` when you already have a fact id and need the whole fact; it returns `{ customer, fact }` with `reasoning` and `source.quote`. Its `include: ["evidence"]` adds the first three excerpts, not every source. To read a long field or the rest of the evidence, pass `part: { field }` (`assertion`, `reasoning`, `quote` or `evidence`) and continue with `part.cursor` and the `nextCursor` of the page before; that result is `{ customer, part }` with no `fact`.
|
|
25
25
|
- Use `outlit_search_customer_context` for fuzzy or thematic questions such as pricing concern, blocked integration, not using, renewal, champion left, negative sentiment, expansion, implementation, or support escalation.
|
|
26
26
|
- Use `outlit_list_sources` to discover the source artifacts available for a customer before retrieving one in full. Narrow with `filters` (`sourceTypes`, `after`, `before`, `participant`, `provider`, `hasTranscript`).
|
|
27
27
|
- Use `outlit_get_source` when a fact or search result needs stronger evidence from the underlying source artifact. Pass the `source { type, id }` that the timeline event, fact, search result or source listing returned, as it came. Content is `content.data.segments`, a page at a time (`content.data.page`).
|
|
@@ -29,7 +29,7 @@ Do not invent customer state when Outlit can answer it. Call out sparse or messy
|
|
|
29
29
|
- Use `outlit_list_features` to inspect the confirmed workspace taxonomy, historical evidence, eligible sources, and event candidates.
|
|
30
30
|
- Use `outlit_create_feature` only when the user explicitly asks to configure one confirmed product capability from one exact event rule. Outlit creates the supporting usage metrics internally.
|
|
31
31
|
- Use `outlit_archive_feature` only when the user explicitly asks to archive a feature and supplies the current opaque id and revision. The MVP has no restore operation and rejects archiving the final active feature.
|
|
32
|
-
- Use `outlit_list_toolsets` when a tool you need is not in your list; `outlit_load_toolset` summarizes one toolset's tools, and with `tools` (at most 10 names) returns their full definitions.
|
|
32
|
+
- Use `outlit_list_toolsets` when a tool you need is not in your list; `outlit_load_toolset` summarizes one toolset's tools, and with `tools` (at most 10 names) returns their full definitions. Pi registers its tools when the session starts, so loading a toolset does not make its tools callable here: tell the user which toolset holds the tool, to enable through the extension's `toolsets` option.
|
|
33
33
|
- Use `outlit_submit_feedback` when the user wants to report an Outlit product bug, idea, or friction. Feedback is product intake, not a support ticket or a guaranteed reply. Put diagnostics in `context`, never secrets or unnecessary customer data.
|
|
34
34
|
|
|
35
35
|
Use customer lookups before SQL. SQL is for aggregates, joins, cohorts, time-series analysis, and custom reporting.
|
|
@@ -69,6 +69,7 @@ For supported query patterns, read [references/sql-reference.md](references/sql-
|
|
|
69
69
|
- Do not send messages, create tasks, update CRM records, or take external actions unless the user explicitly asks and the necessary tools are available.
|
|
70
70
|
- Do not create or archive Features unless the user explicitly asks. Treat feature usage only as observed product evidence.
|
|
71
71
|
- If an Outlit tool errors because `OUTLIT_API_KEY` is missing, tell the user to set `OUTLIT_API_KEY` and retry.
|
|
72
|
+
- A failed call comes back as a tool result `{ "error": { code, message, retryable, requestId, ... } }`, not a crash. Act on it: `validationIssues` say which input to fix and `validValues` what it accepts; `next` names the call to make instead; `missingPermission` is the permission the key lacks (tell the user); `retryAfterSeconds` is how long to wait on a rate limit; `retryable: true` means the same call may work later. Quote `requestId` when you report the failure.
|
|
72
73
|
|
|
73
74
|
## Output
|
|
74
75
|
|