@gleanwork/api-client 0.13.12 → 0.13.13
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/dist/commonjs/hooks/registration.d.ts +1 -1
- package/dist/commonjs/hooks/registration.d.ts.map +1 -1
- package/dist/commonjs/hooks/registration.js +32 -1
- package/dist/commonjs/hooks/registration.js.map +1 -1
- package/dist/commonjs/lib/config.d.ts +2 -2
- package/dist/commonjs/lib/config.js +2 -2
- package/dist/esm/hooks/registration.d.ts +1 -1
- package/dist/esm/hooks/registration.d.ts.map +1 -1
- package/dist/esm/hooks/registration.js +32 -1
- package/dist/esm/hooks/registration.js.map +1 -1
- package/dist/esm/lib/config.d.ts +2 -2
- package/dist/esm/lib/config.js +2 -2
- package/examples/package-lock.json +1 -1
- package/examples/src/agentWithFileUpload.example.ts +32 -0
- package/jsr.json +1 -1
- package/package.json +1 -1
- package/src/hooks/registration.ts +38 -2
- package/src/lib/config.ts +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registration.d.ts","sourceRoot":"","sources":["../../../src/hooks/registration.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,
|
|
1
|
+
{"version":3,"file":"registration.d.ts","sourceRoot":"","sources":["../../../src/hooks/registration.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAkB,MAAM,YAAY,CAAC;AA4CnD,wBAAgB,SAAS,CAAC,KAAK,EAAE,KAAK,QAKrC"}
|
|
@@ -6,10 +6,41 @@ exports.initHooks = initHooks;
|
|
|
6
6
|
* Any hooks you wish to add should be registered in the initHooks function. Feel free to define them
|
|
7
7
|
* in this file or in separate files in the hooks folder.
|
|
8
8
|
*/
|
|
9
|
-
|
|
9
|
+
const agentFileUploadErrorHook = {
|
|
10
|
+
afterError: async (hookCtx, response, error) => {
|
|
11
|
+
if ((hookCtx.operationID === 'createAndWaitRun' ||
|
|
12
|
+
hookCtx.operationID === 'createAndStreamRun') &&
|
|
13
|
+
response?.status === 400) {
|
|
14
|
+
const errorMessage = String(error);
|
|
15
|
+
// The API returns "Not enough user permissions" when it fails to parse the file ID string
|
|
16
|
+
if (errorMessage.includes('permission')) {
|
|
17
|
+
return {
|
|
18
|
+
response,
|
|
19
|
+
error: new Error(`Agent file upload error: When using agents with file inputs, you must follow a two-step process:\n` +
|
|
20
|
+
`\n1. First, upload files using client.chat.uploadFiles():\n` +
|
|
21
|
+
` const uploadResult = await glean.client.chat.uploadFiles({\n` +
|
|
22
|
+
` files: [fileBlob]\n` +
|
|
23
|
+
` });\n` +
|
|
24
|
+
`\n2. Then, pass the returned file IDs (not Blob/File objects) in the input field:\n` +
|
|
25
|
+
` const result = await glean.client.agents.run({\n` +
|
|
26
|
+
` agentId: '<agent-id>',\n` +
|
|
27
|
+
` input: {\n` +
|
|
28
|
+
` myFile: uploadResult.files[0].id // Use the file ID\n` +
|
|
29
|
+
` }\n` +
|
|
30
|
+
` });\n` +
|
|
31
|
+
`\nFor a complete example, see: examples/src/agentWithFileUpload.example.ts\n` +
|
|
32
|
+
`Documentation: https://developers.glean.com/api/client-api/agents/overview\n` +
|
|
33
|
+
`\nOriginal error: ${errorMessage}`),
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return { response, error };
|
|
38
|
+
},
|
|
39
|
+
};
|
|
10
40
|
function initHooks(hooks) {
|
|
11
41
|
// Add hooks by calling hooks.register{ClientInit/BeforeCreateRequest/BeforeRequest/AfterSuccess/AfterError}Hook
|
|
12
42
|
// with an instance of a hook that implements that specific Hook interface
|
|
13
43
|
// Hooks are registered per SDK instance, and are valid for the lifetime of the SDK instance
|
|
44
|
+
hooks.registerAfterErrorHook(agentFileUploadErrorHook);
|
|
14
45
|
}
|
|
15
46
|
//# sourceMappingURL=registration.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registration.js","sourceRoot":"","sources":["../../../src/hooks/registration.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"registration.js","sourceRoot":"","sources":["../../../src/hooks/registration.ts"],"names":[],"mappings":";;AA4CA,8BAKC;AA/CD;;;;GAIG;AAEH,MAAM,wBAAwB,GAAmB;IAC/C,UAAU,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,EAAE;QAC7C,IACE,CAAC,OAAO,CAAC,WAAW,KAAK,kBAAkB;YACzC,OAAO,CAAC,WAAW,KAAK,oBAAoB,CAAC;YAC/C,QAAQ,EAAE,MAAM,KAAK,GAAG,EACxB,CAAC;YACD,MAAM,YAAY,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;YACnC,0FAA0F;YAC1F,IAAI,YAAY,CAAC,QAAQ,CAAC,YAAY,CAAC,EAAE,CAAC;gBACxC,OAAO;oBACL,QAAQ;oBACR,KAAK,EAAE,IAAI,KAAK,CACd,oGAAoG;wBAClG,6DAA6D;wBAC7D,iEAAiE;wBACjE,0BAA0B;wBAC1B,UAAU;wBACV,qFAAqF;wBACrF,qDAAqD;wBACrD,+BAA+B;wBAC/B,iBAAiB;wBACjB,+DAA+D;wBAC/D,UAAU;wBACV,UAAU;wBACV,8EAA8E;wBAC9E,8EAA8E;wBAC9E,qBAAqB,YAAY,EAAE,CACtC;iBACF,CAAC;YACJ,CAAC;QACH,CAAC;QACD,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC;IAC7B,CAAC;CACF,CAAC;AAEF,SAAgB,SAAS,CAAC,KAAY;IACpC,gHAAgH;IAChH,0EAA0E;IAC1E,4FAA4F;IAC5F,KAAK,CAAC,sBAAsB,CAAC,wBAAwB,CAAC,CAAC;AACzD,CAAC"}
|
|
@@ -35,8 +35,8 @@ export declare function serverURLFromOptions(options: SDKOptions): URL | null;
|
|
|
35
35
|
export declare const SDK_METADATA: {
|
|
36
36
|
readonly language: "typescript";
|
|
37
37
|
readonly openapiDocVersion: "0.9.0";
|
|
38
|
-
readonly sdkVersion: "0.13.
|
|
38
|
+
readonly sdkVersion: "0.13.13";
|
|
39
39
|
readonly genVersion: "2.760.2";
|
|
40
|
-
readonly userAgent: "speakeasy-sdk/typescript 0.13.
|
|
40
|
+
readonly userAgent: "speakeasy-sdk/typescript 0.13.13 2.760.2 0.9.0 @gleanwork/api-client";
|
|
41
41
|
};
|
|
42
42
|
//# sourceMappingURL=config.d.ts.map
|
|
@@ -34,8 +34,8 @@ function serverURLFromOptions(options) {
|
|
|
34
34
|
exports.SDK_METADATA = {
|
|
35
35
|
language: "typescript",
|
|
36
36
|
openapiDocVersion: "0.9.0",
|
|
37
|
-
sdkVersion: "0.13.
|
|
37
|
+
sdkVersion: "0.13.13",
|
|
38
38
|
genVersion: "2.760.2",
|
|
39
|
-
userAgent: "speakeasy-sdk/typescript 0.13.
|
|
39
|
+
userAgent: "speakeasy-sdk/typescript 0.13.13 2.760.2 0.9.0 @gleanwork/api-client",
|
|
40
40
|
};
|
|
41
41
|
//# sourceMappingURL=config.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registration.d.ts","sourceRoot":"","sources":["../../../src/hooks/registration.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,
|
|
1
|
+
{"version":3,"file":"registration.d.ts","sourceRoot":"","sources":["../../../src/hooks/registration.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAkB,MAAM,YAAY,CAAC;AA4CnD,wBAAgB,SAAS,CAAC,KAAK,EAAE,KAAK,QAKrC"}
|
|
@@ -3,10 +3,41 @@
|
|
|
3
3
|
* Any hooks you wish to add should be registered in the initHooks function. Feel free to define them
|
|
4
4
|
* in this file or in separate files in the hooks folder.
|
|
5
5
|
*/
|
|
6
|
-
|
|
6
|
+
const agentFileUploadErrorHook = {
|
|
7
|
+
afterError: async (hookCtx, response, error) => {
|
|
8
|
+
if ((hookCtx.operationID === 'createAndWaitRun' ||
|
|
9
|
+
hookCtx.operationID === 'createAndStreamRun') &&
|
|
10
|
+
response?.status === 400) {
|
|
11
|
+
const errorMessage = String(error);
|
|
12
|
+
// The API returns "Not enough user permissions" when it fails to parse the file ID string
|
|
13
|
+
if (errorMessage.includes('permission')) {
|
|
14
|
+
return {
|
|
15
|
+
response,
|
|
16
|
+
error: new Error(`Agent file upload error: When using agents with file inputs, you must follow a two-step process:\n` +
|
|
17
|
+
`\n1. First, upload files using client.chat.uploadFiles():\n` +
|
|
18
|
+
` const uploadResult = await glean.client.chat.uploadFiles({\n` +
|
|
19
|
+
` files: [fileBlob]\n` +
|
|
20
|
+
` });\n` +
|
|
21
|
+
`\n2. Then, pass the returned file IDs (not Blob/File objects) in the input field:\n` +
|
|
22
|
+
` const result = await glean.client.agents.run({\n` +
|
|
23
|
+
` agentId: '<agent-id>',\n` +
|
|
24
|
+
` input: {\n` +
|
|
25
|
+
` myFile: uploadResult.files[0].id // Use the file ID\n` +
|
|
26
|
+
` }\n` +
|
|
27
|
+
` });\n` +
|
|
28
|
+
`\nFor a complete example, see: examples/src/agentWithFileUpload.example.ts\n` +
|
|
29
|
+
`Documentation: https://developers.glean.com/api/client-api/agents/overview\n` +
|
|
30
|
+
`\nOriginal error: ${errorMessage}`),
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return { response, error };
|
|
35
|
+
},
|
|
36
|
+
};
|
|
7
37
|
export function initHooks(hooks) {
|
|
8
38
|
// Add hooks by calling hooks.register{ClientInit/BeforeCreateRequest/BeforeRequest/AfterSuccess/AfterError}Hook
|
|
9
39
|
// with an instance of a hook that implements that specific Hook interface
|
|
10
40
|
// Hooks are registered per SDK instance, and are valid for the lifetime of the SDK instance
|
|
41
|
+
hooks.registerAfterErrorHook(agentFileUploadErrorHook);
|
|
11
42
|
}
|
|
12
43
|
//# sourceMappingURL=registration.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registration.js","sourceRoot":"","sources":["../../../src/hooks/registration.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AAEH,
|
|
1
|
+
{"version":3,"file":"registration.js","sourceRoot":"","sources":["../../../src/hooks/registration.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AAEH,MAAM,wBAAwB,GAAmB;IAC/C,UAAU,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,EAAE;QAC7C,IACE,CAAC,OAAO,CAAC,WAAW,KAAK,kBAAkB;YACzC,OAAO,CAAC,WAAW,KAAK,oBAAoB,CAAC;YAC/C,QAAQ,EAAE,MAAM,KAAK,GAAG,EACxB,CAAC;YACD,MAAM,YAAY,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;YACnC,0FAA0F;YAC1F,IAAI,YAAY,CAAC,QAAQ,CAAC,YAAY,CAAC,EAAE,CAAC;gBACxC,OAAO;oBACL,QAAQ;oBACR,KAAK,EAAE,IAAI,KAAK,CACd,oGAAoG;wBAClG,6DAA6D;wBAC7D,iEAAiE;wBACjE,0BAA0B;wBAC1B,UAAU;wBACV,qFAAqF;wBACrF,qDAAqD;wBACrD,+BAA+B;wBAC/B,iBAAiB;wBACjB,+DAA+D;wBAC/D,UAAU;wBACV,UAAU;wBACV,8EAA8E;wBAC9E,8EAA8E;wBAC9E,qBAAqB,YAAY,EAAE,CACtC;iBACF,CAAC;YACJ,CAAC;QACH,CAAC;QACD,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC;IAC7B,CAAC;CACF,CAAC;AAEF,MAAM,UAAU,SAAS,CAAC,KAAY;IACpC,gHAAgH;IAChH,0EAA0E;IAC1E,4FAA4F;IAC5F,KAAK,CAAC,sBAAsB,CAAC,wBAAwB,CAAC,CAAC;AACzD,CAAC"}
|
package/dist/esm/lib/config.d.ts
CHANGED
|
@@ -35,8 +35,8 @@ export declare function serverURLFromOptions(options: SDKOptions): URL | null;
|
|
|
35
35
|
export declare const SDK_METADATA: {
|
|
36
36
|
readonly language: "typescript";
|
|
37
37
|
readonly openapiDocVersion: "0.9.0";
|
|
38
|
-
readonly sdkVersion: "0.13.
|
|
38
|
+
readonly sdkVersion: "0.13.13";
|
|
39
39
|
readonly genVersion: "2.760.2";
|
|
40
|
-
readonly userAgent: "speakeasy-sdk/typescript 0.13.
|
|
40
|
+
readonly userAgent: "speakeasy-sdk/typescript 0.13.13 2.760.2 0.9.0 @gleanwork/api-client";
|
|
41
41
|
};
|
|
42
42
|
//# sourceMappingURL=config.d.ts.map
|
package/dist/esm/lib/config.js
CHANGED
|
@@ -30,8 +30,8 @@ export function serverURLFromOptions(options) {
|
|
|
30
30
|
export const SDK_METADATA = {
|
|
31
31
|
language: "typescript",
|
|
32
32
|
openapiDocVersion: "0.9.0",
|
|
33
|
-
sdkVersion: "0.13.
|
|
33
|
+
sdkVersion: "0.13.13",
|
|
34
34
|
genVersion: "2.760.2",
|
|
35
|
-
userAgent: "speakeasy-sdk/typescript 0.13.
|
|
35
|
+
userAgent: "speakeasy-sdk/typescript 0.13.13 2.760.2 0.9.0 @gleanwork/api-client",
|
|
36
36
|
};
|
|
37
37
|
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { config } from 'dotenv';
|
|
2
|
+
config();
|
|
3
|
+
import { Glean } from '@gleanwork/api-client';
|
|
4
|
+
|
|
5
|
+
const glean = new Glean({
|
|
6
|
+
domain: process.env['GLEAN_DOMAIN'] ?? '',
|
|
7
|
+
apiToken: process.env['GLEAN_BEARER_AUTH'] ?? '',
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
async function run() {
|
|
11
|
+
// 1. Upload the file first
|
|
12
|
+
const fileBlob = new Blob(['name,role\nAlice,Engineer'], { type: 'text/csv' });
|
|
13
|
+
|
|
14
|
+
const uploadResponse = await glean.client.chat.uploadFiles({
|
|
15
|
+
files: [fileBlob as any],
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
const fileId = uploadResponse.files[0].id;
|
|
19
|
+
console.log(`File uploaded: ${fileId}`);
|
|
20
|
+
|
|
21
|
+
// 2. Pass the file ID (NOT the blob) to the agent
|
|
22
|
+
const result = await glean.client.agents.run({
|
|
23
|
+
agentId: process.env['GLEAN_AGENT_ID']!,
|
|
24
|
+
input: {
|
|
25
|
+
file_input: fileId, // ✅ Pass the ID string
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
console.log('Agent run result:', result);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
run();
|
package/jsr.json
CHANGED
package/package.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Hooks } from
|
|
1
|
+
import { Hooks, AfterErrorHook } from './types.js';
|
|
2
2
|
|
|
3
3
|
/*
|
|
4
4
|
* This file is only ever generated once on the first generation and then is free to be modified.
|
|
@@ -6,9 +6,45 @@ import { Hooks } from "./types.js";
|
|
|
6
6
|
* in this file or in separate files in the hooks folder.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
const agentFileUploadErrorHook: AfterErrorHook = {
|
|
10
|
+
afterError: async (hookCtx, response, error) => {
|
|
11
|
+
if (
|
|
12
|
+
(hookCtx.operationID === 'createAndWaitRun' ||
|
|
13
|
+
hookCtx.operationID === 'createAndStreamRun') &&
|
|
14
|
+
response?.status === 400
|
|
15
|
+
) {
|
|
16
|
+
const errorMessage = String(error);
|
|
17
|
+
// The API returns "Not enough user permissions" when it fails to parse the file ID string
|
|
18
|
+
if (errorMessage.includes('permission')) {
|
|
19
|
+
return {
|
|
20
|
+
response,
|
|
21
|
+
error: new Error(
|
|
22
|
+
`Agent file upload error: When using agents with file inputs, you must follow a two-step process:\n` +
|
|
23
|
+
`\n1. First, upload files using client.chat.uploadFiles():\n` +
|
|
24
|
+
` const uploadResult = await glean.client.chat.uploadFiles({\n` +
|
|
25
|
+
` files: [fileBlob]\n` +
|
|
26
|
+
` });\n` +
|
|
27
|
+
`\n2. Then, pass the returned file IDs (not Blob/File objects) in the input field:\n` +
|
|
28
|
+
` const result = await glean.client.agents.run({\n` +
|
|
29
|
+
` agentId: '<agent-id>',\n` +
|
|
30
|
+
` input: {\n` +
|
|
31
|
+
` myFile: uploadResult.files[0].id // Use the file ID\n` +
|
|
32
|
+
` }\n` +
|
|
33
|
+
` });\n` +
|
|
34
|
+
`\nFor a complete example, see: examples/src/agentWithFileUpload.example.ts\n` +
|
|
35
|
+
`Documentation: https://developers.glean.com/api/client-api/agents/overview\n` +
|
|
36
|
+
`\nOriginal error: ${errorMessage}`
|
|
37
|
+
),
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return { response, error };
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
|
|
10
45
|
export function initHooks(hooks: Hooks) {
|
|
11
46
|
// Add hooks by calling hooks.register{ClientInit/BeforeCreateRequest/BeforeRequest/AfterSuccess/AfterError}Hook
|
|
12
47
|
// with an instance of a hook that implements that specific Hook interface
|
|
13
48
|
// Hooks are registered per SDK instance, and are valid for the lifetime of the SDK instance
|
|
49
|
+
hooks.registerAfterErrorHook(agentFileUploadErrorHook);
|
|
14
50
|
}
|
package/src/lib/config.ts
CHANGED
|
@@ -68,8 +68,8 @@ export function serverURLFromOptions(options: SDKOptions): URL | null {
|
|
|
68
68
|
export const SDK_METADATA = {
|
|
69
69
|
language: "typescript",
|
|
70
70
|
openapiDocVersion: "0.9.0",
|
|
71
|
-
sdkVersion: "0.13.
|
|
71
|
+
sdkVersion: "0.13.13",
|
|
72
72
|
genVersion: "2.760.2",
|
|
73
73
|
userAgent:
|
|
74
|
-
"speakeasy-sdk/typescript 0.13.
|
|
74
|
+
"speakeasy-sdk/typescript 0.13.13 2.760.2 0.9.0 @gleanwork/api-client",
|
|
75
75
|
} as const;
|