@outlit/pi 2.2.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 CHANGED
@@ -19,10 +19,11 @@ 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
- - `outlit_list_users`
25
+ - `outlit_list_customer_fields`
26
+ - `outlit_list_people`
26
27
  - `outlit_get_customer`
27
28
  - `outlit_get_timeline`
28
29
  - `outlit_list_facts`
@@ -30,10 +31,14 @@ The default extension registers the default customer intelligence tools from `@o
30
31
  - `outlit_get_source`
31
32
  - `outlit_list_sources`
32
33
  - `outlit_search_customer_context`
34
+ - `outlit_list_toolsets`
35
+ - `outlit_load_toolset`
33
36
 
34
- 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 customer relationship and Attention reads, customer ownership and access actions, product-facing Feature list, create, archive, and customer-usage tools, plus safe integration setup, destination, activation, workspace-settings actions, and `outlit_submit_feedback` product feedback intake. The default and analytical policies remain unchanged.
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).
35
38
 
36
- 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_schema` and `outlit_query` without exposing every customer tool:
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.
40
+
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:
37
42
 
38
43
  ```ts
39
44
  import { analyticalToolNames, createOutlitPiExtension } from "@outlit/pi"
@@ -53,11 +58,25 @@ pi install npm:@outlit/pi
53
58
 
54
59
  The skill gives the model generic guidance for choosing between customer records, users, timelines, facts, search, sources, and SQL when SQL tools are enabled. It does not add CLI or MCP instructions; it assumes the Outlit tools registered by this package are the available interface.
55
60
 
56
- The facts tool supports `factTypes` filters for narrowing structured evidence. Public filters include customer-memory facts and relationship transitions such as `CONTACT_DEPARTURE`, `CONTACT_POSITION_CHANGE`, and `CONTACT_DISENGAGEMENT`. Anomaly detector fact types are not supported as public filters because customers may not have configured core actions, activation paths, or funnels.
61
+ The facts tool supports `filters.types` for narrowing structured evidence (all filter values are lowercase). Public filters include customer-memory facts and relationship transitions such as `contact_departure`, `contact_position_change`, and `contact_disengagement`. Anomaly detector fact types are not supported as public filters because customers may not have configured core actions, activation paths, or funnels.
57
62
 
58
63
  ## Custom Toolsets
59
64
 
60
- Create a small Pi extension when you want a narrower or broader toolset:
65
+ Create a small Pi extension when you want a narrower or broader toolset. Core groups its tools into toolsets (`core`, `work`, `identity`, `admin`, `meta`); `toolsets` registers every tool in the ones you name, and combines with `toolNames` when you pass both:
66
+
67
+ ```ts
68
+ import { createOutlitPiExtension } from "@outlit/pi"
69
+
70
+ export default createOutlitPiExtension({
71
+ toolsets: ["core", "work"],
72
+ })
73
+ ```
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
+
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.
78
+
79
+ To register every Pi-supported tool:
61
80
 
62
81
  ```ts
63
82
  import { createOutlitPiExtension, piToolNames } from "@outlit/pi"
@@ -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)) {
@@ -38,9 +131,7 @@ function createOutlitPiExtension(options = {}) {
38
131
  };
39
132
  }
40
133
  function createOutlitPiTools(options = {}) {
41
- return resolveToolNames(options.toolNames).map(
42
- (toolName) => createOutlitPiTool(toolName, options)
43
- );
134
+ return resolveToolNames(options).map((toolName) => createOutlitPiTool(toolName, options));
44
135
  }
45
136
  function createOutlitPiTool(toolName, options = {}) {
46
137
  if (!(0, import_tools.isPublicToolName)(toolName)) {
@@ -58,13 +149,28 @@ function createOutlitPiTool(toolName, options = {}) {
58
149
  promptSnippet: `${label}: ${firstLine(contract.description)}`,
59
150
  parameters: toPiToolParameters(contract.inputSchema),
60
151
  async execute(_toolCallId, params) {
152
+ let responseInfo;
61
153
  const client = (0, import_tools.createOutlitClient)({
62
154
  apiKey: resolveApiKey(options),
63
155
  baseUrl: resolveBaseUrl(options),
64
- fetch: options.fetch
156
+ fetch: options.fetch,
157
+ client: OUTLIT_PI_CLIENT,
158
+ onResponse: (info) => {
159
+ responseInfo = info;
160
+ }
65
161
  });
66
- const result = await client.callTool(toolName, normalizeToolInput(params));
67
- return formatToolResult(toolName, result);
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
+ }
68
174
  }
69
175
  };
70
176
  }
@@ -78,8 +184,11 @@ function toPiToolParameters(inputSchema) {
78
184
  function formatOutlitToolLabel(toolName) {
79
185
  return toolName.split("_").map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join(" ");
80
186
  }
81
- function resolveToolNames(toolNames) {
82
- const names = toolNames ?? import_tools.defaultToolNames;
187
+ function resolveToolNames(options) {
188
+ const names = [
189
+ ...options.toolNames ?? (options.toolsets ? [] : piDefaultToolNames),
190
+ ...options.toolsets ? (0, import_tools.toolNamesInToolsets)(options.toolsets) : []
191
+ ];
83
192
  return [...new Set(names)].map((name) => {
84
193
  if (!(0, import_tools.isPublicToolName)(name)) {
85
194
  throw new Error(`Unknown Outlit public tool: ${name}`);
@@ -110,12 +219,54 @@ function normalizeToolInput(params) {
110
219
  }
111
220
  return params;
112
221
  }
113
- function formatToolResult(toolName, result) {
222
+ function responseNotices(info) {
223
+ if (!info) return [];
224
+ return [
225
+ ...info.deprecation ? [`${info.deprecation.message} (until ${info.deprecation.until})`] : [],
226
+ ...info.notices
227
+ ];
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
+ }
258
+ function formatToolResult(toolName, result, info) {
259
+ const notices = responseNotices(info);
114
260
  return {
115
- content: [{ type: "text", text: JSON.stringify(result, null, 2) ?? String(result) }],
261
+ content: [
262
+ { type: "text", text: JSON.stringify(result, null, 2) ?? String(result) },
263
+ // After the result, so a reader of the first block still gets the JSON alone.
264
+ ...notices.length > 0 ? [{ type: "text", text: `Notice: ${notices.join(" ")}` }] : []
265
+ ],
116
266
  details: {
117
267
  toolName,
118
- result
268
+ result,
269
+ ...responseIds(info)
119
270
  }
120
271
  };
121
272
  }
@@ -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 PiToolName,\n piToolNames,\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\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.toolNames).map((toolName) =>\n createOutlitPiTool(toolName, options),\n )\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 const client = createOutlitClient({\n apiKey: resolveApiKey(options),\n baseUrl: resolveBaseUrl(options),\n fetch: options.fetch,\n })\n const result = await client.callTool(toolName, normalizeToolInput(params))\n\n return formatToolResult(toolName, result)\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(toolNames: readonly PiToolName[] | undefined): PiToolName[] {\n const names = toolNames ?? defaultToolNames\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\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\nfunction formatToolResult(\n toolName: PiToolName,\n result: unknown,\n): AgentToolResult<OutlitPiToolDetails> {\n return {\n content: [{ type: \"text\", text: JSON.stringify(result, null, 2) ?? String(result) }],\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 {\n analyticalToolNames,\n defaultToolNames,\n piToolNames,\n piToolNames as allPublicToolNames,\n sqlToolNames,\n} from \"@outlit/tools\"\n\nexport default createOutlitPiExtension()\n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AwC;AAAA,EAC9D;AAEA,SAAO;AACT;AAEA,SAAS,iBACP,UACA,QACsC;AACtC,SAAO;AAAA,IACL,SAAS,CAAC,EAAE,MAAM,QAAQ,MAAM,KAAK,UAAU,QAAQ,MAAM,CAAC,KAAK,OAAO,MAAM,EAAE,CAAC;AAAA,IACnF,SAAS;AAAA,MACP;AAAA,MACA;AAAA,IACF;AAAA,EACF;AACF;AAEA,SAAS,UAAU,OAAuB;AACxC,SAAO,MAAM,MAAM,MAAM,CAAC,EAAE,CAAC,KAAK;AACpC;AAaA,IAAO,cAAQ,wBAAwB;;;AD5KvC,IAAO,oBAAQ,wBAAwB;","names":["import_tools"]}
1
+ {"version":3,"sources":["../src/extension.ts","../src/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;AA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,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;;;AD1SvC,IAAO,oBAAQ,wBAAwB;","names":["import_tools"]}
package/dist/extension.js CHANGED
@@ -4,19 +4,115 @@ import {
4
4
  DEFAULT_OUTLIT_API_URL,
5
5
  defaultToolNames,
6
6
  getPublicToolContract,
7
+ isOutlitToolsApiError,
7
8
  isPublicToolName,
8
- piToolNames
9
+ piToolNames,
10
+ toolNamesInToolsets
9
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
10
99
  import {
11
100
  analyticalToolNames,
12
101
  defaultToolNames as defaultToolNames2,
13
102
  piToolNames as piToolNames2,
14
103
  piToolNames as piToolNames3,
15
- sqlToolNames
104
+ sqlToolNames,
105
+ toolsetNames
16
106
  } from "@outlit/tools";
17
107
  var OUTLIT_API_KEY_ENV = "OUTLIT_API_KEY";
18
108
  var OUTLIT_API_URL_ENV = "OUTLIT_API_URL";
109
+ var OUTLIT_PI_CLIENT = `@outlit/pi/${package_default.version}`;
19
110
  var piToolNameSet = new Set(piToolNames);
111
+ var piDefaultToolNames = [
112
+ ...defaultToolNames,
113
+ "outlit_list_toolsets",
114
+ "outlit_load_toolset"
115
+ ];
20
116
  function createOutlitPiExtension(options = {}) {
21
117
  return function outlitPiExtension(pi) {
22
118
  for (const tool of createOutlitPiTools(options)) {
@@ -25,9 +121,7 @@ function createOutlitPiExtension(options = {}) {
25
121
  };
26
122
  }
27
123
  function createOutlitPiTools(options = {}) {
28
- return resolveToolNames(options.toolNames).map(
29
- (toolName) => createOutlitPiTool(toolName, options)
30
- );
124
+ return resolveToolNames(options).map((toolName) => createOutlitPiTool(toolName, options));
31
125
  }
32
126
  function createOutlitPiTool(toolName, options = {}) {
33
127
  if (!isPublicToolName(toolName)) {
@@ -45,13 +139,28 @@ function createOutlitPiTool(toolName, options = {}) {
45
139
  promptSnippet: `${label}: ${firstLine(contract.description)}`,
46
140
  parameters: toPiToolParameters(contract.inputSchema),
47
141
  async execute(_toolCallId, params) {
142
+ let responseInfo;
48
143
  const client = createOutlitClient({
49
144
  apiKey: resolveApiKey(options),
50
145
  baseUrl: resolveBaseUrl(options),
51
- fetch: options.fetch
146
+ fetch: options.fetch,
147
+ client: OUTLIT_PI_CLIENT,
148
+ onResponse: (info) => {
149
+ responseInfo = info;
150
+ }
52
151
  });
53
- const result = await client.callTool(toolName, normalizeToolInput(params));
54
- return formatToolResult(toolName, result);
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
+ }
55
164
  }
56
165
  };
57
166
  }
@@ -65,8 +174,11 @@ function toPiToolParameters(inputSchema) {
65
174
  function formatOutlitToolLabel(toolName) {
66
175
  return toolName.split("_").map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join(" ");
67
176
  }
68
- function resolveToolNames(toolNames) {
69
- const names = toolNames ?? defaultToolNames;
177
+ function resolveToolNames(options) {
178
+ const names = [
179
+ ...options.toolNames ?? (options.toolsets ? [] : piDefaultToolNames),
180
+ ...options.toolsets ? toolNamesInToolsets(options.toolsets) : []
181
+ ];
70
182
  return [...new Set(names)].map((name) => {
71
183
  if (!isPublicToolName(name)) {
72
184
  throw new Error(`Unknown Outlit public tool: ${name}`);
@@ -97,12 +209,54 @@ function normalizeToolInput(params) {
97
209
  }
98
210
  return params;
99
211
  }
100
- function formatToolResult(toolName, result) {
212
+ function responseNotices(info) {
213
+ if (!info) return [];
214
+ return [
215
+ ...info.deprecation ? [`${info.deprecation.message} (until ${info.deprecation.until})`] : [],
216
+ ...info.notices
217
+ ];
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
+ }
248
+ function formatToolResult(toolName, result, info) {
249
+ const notices = responseNotices(info);
101
250
  return {
102
- content: [{ type: "text", text: JSON.stringify(result, null, 2) ?? String(result) }],
251
+ content: [
252
+ { type: "text", text: JSON.stringify(result, null, 2) ?? String(result) },
253
+ // After the result, so a reader of the first block still gets the JSON alone.
254
+ ...notices.length > 0 ? [{ type: "text", text: `Notice: ${notices.join(" ")}` }] : []
255
+ ],
103
256
  details: {
104
257
  toolName,
105
- result
258
+ result,
259
+ ...responseIds(info)
106
260
  }
107
261
  };
108
262
  }
@@ -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 PiToolName,\n piToolNames,\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\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.toolNames).map((toolName) =>\n createOutlitPiTool(toolName, options),\n )\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 const client = createOutlitClient({\n apiKey: resolveApiKey(options),\n baseUrl: resolveBaseUrl(options),\n fetch: options.fetch,\n })\n const result = await client.callTool(toolName, normalizeToolInput(params))\n\n return formatToolResult(toolName, result)\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(toolNames: readonly PiToolName[] | undefined): PiToolName[] {\n const names = toolNames ?? defaultToolNames\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\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\nfunction formatToolResult(\n toolName: PiToolName,\n result: unknown,\n): AgentToolResult<OutlitPiToolDetails> {\n return {\n content: [{ type: \"text\", text: JSON.stringify(result, null, 2) ?? String(result) }],\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 {\n analyticalToolNames,\n defaultToolNames,\n piToolNames,\n piToolNames as allPublicToolNames,\n sqlToolNames,\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,EAGA;AAAA,OACK;AA4JP;AAAA,EACE;AAAA,EACA,oBAAAA;AAAA,EACA,eAAAC;AAAA,EACe,eAAfA;AAAA,EACA;AAAA,OACK;AA/JA,IAAM,qBAAqB;AAC3B,IAAM,qBAAqB;AAElC,IAAM,gBAAgB,IAAI,IAAY,WAAW;AAkB1C,SAAS,wBAAwB,UAAoC,CAAC,GAAG;AAC9E,SAAO,SAAS,kBAAk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F;AAEA,SAAS,UAAU,OAAuB;AACxC,SAAO,MAAM,MAAM,MAAM,CAAC,EAAE,CAAC,KAAK;AACpC;AAaA,IAAO,cAAQ,wBAAwB;;;AC5KvC,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;AAA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