@salesforce/sfdx-agent-harness-openai 0.0.1

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.
Files changed (53) hide show
  1. package/CHANGELOG.md +37 -0
  2. package/LICENSE.txt +21 -0
  3. package/README.md +55 -0
  4. package/dist/gen-sink.d.ts +8 -0
  5. package/dist/gen-sink.js +13 -0
  6. package/dist/gen-sink.js.map +1 -0
  7. package/dist/index.d.ts +3 -0
  8. package/dist/index.js +16 -0
  9. package/dist/index.js.map +1 -0
  10. package/dist/mcp-error-classifier.d.ts +36 -0
  11. package/dist/mcp-error-classifier.js +166 -0
  12. package/dist/mcp-error-classifier.js.map +1 -0
  13. package/dist/openai-agents-harness-factory.d.ts +36 -0
  14. package/dist/openai-agents-harness-factory.js +39 -0
  15. package/dist/openai-agents-harness-factory.js.map +1 -0
  16. package/dist/openai-agents-harness.d.ts +302 -0
  17. package/dist/openai-agents-harness.js +1014 -0
  18. package/dist/openai-agents-harness.js.map +1 -0
  19. package/dist/openai-approval-coordinator.d.ts +231 -0
  20. package/dist/openai-approval-coordinator.js +422 -0
  21. package/dist/openai-approval-coordinator.js.map +1 -0
  22. package/dist/openai-built-in-policies.d.ts +29 -0
  23. package/dist/openai-built-in-policies.js +33 -0
  24. package/dist/openai-built-in-policies.js.map +1 -0
  25. package/dist/openai-event-adapter.d.ts +119 -0
  26. package/dist/openai-event-adapter.js +322 -0
  27. package/dist/openai-event-adapter.js.map +1 -0
  28. package/dist/openai-mcp-config-mapper.d.ts +58 -0
  29. package/dist/openai-mcp-config-mapper.js +133 -0
  30. package/dist/openai-mcp-config-mapper.js.map +1 -0
  31. package/dist/openai-mcp-state.d.ts +67 -0
  32. package/dist/openai-mcp-state.js +6 -0
  33. package/dist/openai-mcp-state.js.map +1 -0
  34. package/dist/openai-message-mapper.d.ts +79 -0
  35. package/dist/openai-message-mapper.js +374 -0
  36. package/dist/openai-message-mapper.js.map +1 -0
  37. package/dist/openai-model-provider.d.ts +46 -0
  38. package/dist/openai-model-provider.js +144 -0
  39. package/dist/openai-model-provider.js.map +1 -0
  40. package/dist/openai-session-store.d.ts +149 -0
  41. package/dist/openai-session-store.js +328 -0
  42. package/dist/openai-session-store.js.map +1 -0
  43. package/dist/openai-tool-mapper.d.ts +121 -0
  44. package/dist/openai-tool-mapper.js +231 -0
  45. package/dist/openai-tool-mapper.js.map +1 -0
  46. package/dist/openai-tool-redaction.d.ts +55 -0
  47. package/dist/openai-tool-redaction.js +82 -0
  48. package/dist/openai-tool-redaction.js.map +1 -0
  49. package/dist/test/tsconfig.tsbuildinfo +1 -0
  50. package/dist/text-stream.d.ts +30 -0
  51. package/dist/text-stream.js +103 -0
  52. package/dist/text-stream.js.map +1 -0
  53. package/package.json +66 -0
@@ -0,0 +1,30 @@
1
+ import type { ChatEvent } from '@salesforce/sfdx-agent-sdk';
2
+ /**
3
+ * Tees a `ChatEvent` source into the `eventStream` / `textStream` pair the SDK's
4
+ * `ChatStreamResult` contract requires. The OpenAI harness owns the iteration
5
+ * loop over the `@openai/agents` run stream, so it has to derive `textStream`
6
+ * itself rather than getting two parallel streams from the runtime.
7
+ *
8
+ * Iterating either of the returned streams starts a single shared pump that
9
+ * drains the source generator once and fans events out to two internal
10
+ * buffers — one for the full event stream, one filtered to `text-delta`
11
+ * texts. Both streams can be iterated independently or concurrently. If only
12
+ * one is iterated, the other's buffer accumulates until the source ends; the
13
+ * bound that makes this safe is the SDK invariant that every chat turn ends
14
+ * with exactly one terminal `finish` event, so the source always completes
15
+ * within one bounded chat turn.
16
+ *
17
+ * Errors raised while iterating the source are not expected on the harness code
18
+ * path: the `stream()` pump catches underlying exceptions and pushes a
19
+ * synthetic `error` + `finish` `ChatEvent` pair onto the sink instead of
20
+ * throwing. As a defense in depth, a thrown error from the source is forwarded
21
+ * to the primary stream and ends the derived stream silently, so a regression
22
+ * that starts throwing here doesn't deadlock either consumer.
23
+ *
24
+ * Internal to `@salesforce/sfdx-agent-harness-openai`; not part of the public
25
+ * harness surface.
26
+ */
27
+ export declare function teeTextStream(source: AsyncGenerator<ChatEvent>): {
28
+ eventStream: AsyncGenerator<ChatEvent>;
29
+ textStream: AsyncGenerator<string>;
30
+ };
@@ -0,0 +1,103 @@
1
+ /*
2
+ * Copyright 2026, Salesforce, Inc. All rights reserved.
3
+ * See LICENSE.txt for license terms.
4
+ */
5
+ /**
6
+ * Tees a `ChatEvent` source into the `eventStream` / `textStream` pair the SDK's
7
+ * `ChatStreamResult` contract requires. The OpenAI harness owns the iteration
8
+ * loop over the `@openai/agents` run stream, so it has to derive `textStream`
9
+ * itself rather than getting two parallel streams from the runtime.
10
+ *
11
+ * Iterating either of the returned streams starts a single shared pump that
12
+ * drains the source generator once and fans events out to two internal
13
+ * buffers — one for the full event stream, one filtered to `text-delta`
14
+ * texts. Both streams can be iterated independently or concurrently. If only
15
+ * one is iterated, the other's buffer accumulates until the source ends; the
16
+ * bound that makes this safe is the SDK invariant that every chat turn ends
17
+ * with exactly one terminal `finish` event, so the source always completes
18
+ * within one bounded chat turn.
19
+ *
20
+ * Errors raised while iterating the source are not expected on the harness code
21
+ * path: the `stream()` pump catches underlying exceptions and pushes a
22
+ * synthetic `error` + `finish` `ChatEvent` pair onto the sink instead of
23
+ * throwing. As a defense in depth, a thrown error from the source is forwarded
24
+ * to the primary stream and ends the derived stream silently, so a regression
25
+ * that starts throwing here doesn't deadlock either consumer.
26
+ *
27
+ * Internal to `@salesforce/sfdx-agent-harness-openai`; not part of the public
28
+ * harness surface.
29
+ */
30
+ export function teeTextStream(source) {
31
+ const eventBuf = [];
32
+ const textBuf = [];
33
+ let pumpStarted = false;
34
+ let pumpDone = false;
35
+ let pumpError;
36
+ let eventWaiter = null;
37
+ let textWaiter = null;
38
+ const wakeAll = () => {
39
+ eventWaiter?.();
40
+ eventWaiter = null;
41
+ textWaiter?.();
42
+ textWaiter = null;
43
+ };
44
+ const startPump = () => {
45
+ if (pumpStarted)
46
+ return;
47
+ pumpStarted = true;
48
+ void (async () => {
49
+ try {
50
+ for await (const event of source) {
51
+ eventBuf.push(event);
52
+ eventWaiter?.();
53
+ eventWaiter = null;
54
+ if (event.type === 'text-delta') {
55
+ textBuf.push(event.text);
56
+ textWaiter?.();
57
+ textWaiter = null;
58
+ }
59
+ }
60
+ }
61
+ catch (err) {
62
+ pumpError = err;
63
+ }
64
+ finally {
65
+ pumpDone = true;
66
+ wakeAll();
67
+ }
68
+ })();
69
+ };
70
+ async function* eventStream() {
71
+ startPump();
72
+ while (true) {
73
+ if (eventBuf.length > 0) {
74
+ yield eventBuf.shift();
75
+ continue;
76
+ }
77
+ if (pumpDone) {
78
+ if (pumpError !== undefined)
79
+ throw pumpError;
80
+ return;
81
+ }
82
+ await new Promise((resolve) => {
83
+ eventWaiter = resolve;
84
+ });
85
+ }
86
+ }
87
+ async function* textStream() {
88
+ startPump();
89
+ while (true) {
90
+ if (textBuf.length > 0) {
91
+ yield textBuf.shift();
92
+ continue;
93
+ }
94
+ if (pumpDone)
95
+ return;
96
+ await new Promise((resolve) => {
97
+ textWaiter = resolve;
98
+ });
99
+ }
100
+ }
101
+ return { eventStream: eventStream(), textStream: textStream() };
102
+ }
103
+ //# sourceMappingURL=text-stream.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"text-stream.js","sourceRoot":"","sources":["../src/text-stream.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,UAAU,aAAa,CAAC,MAAiC;IAI3D,MAAM,QAAQ,GAAgB,EAAE,CAAC;IACjC,MAAM,OAAO,GAAa,EAAE,CAAC;IAC7B,IAAI,WAAW,GAAG,KAAK,CAAC;IACxB,IAAI,QAAQ,GAAG,KAAK,CAAC;IACrB,IAAI,SAAkB,CAAC;IACvB,IAAI,WAAW,GAAwB,IAAI,CAAC;IAC5C,IAAI,UAAU,GAAwB,IAAI,CAAC;IAE3C,MAAM,OAAO,GAAG,GAAS,EAAE;QACvB,WAAW,E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EAAE;gBAChC,WAAW,GAAG,OAAO,CAAC;YAC1B,CAAC,CAAC,CAAC;QACP,CAAC;IACL,CAAC;IAED,KAAK,SAAS,CAAC,CAAC,UAAU;QACtB,SAAS,EAAE,CAAC;QACZ,OAAO,IAAI,EAAE,CAAC;YACV,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBACrB,MAAM,OAAO,CAAC,KAAK,EAAY,CAAC;gBAChC,SAAS;YACb,CAAC;YACD,IAAI,QAAQ;gBAAE,OAAO;YACrB,MAAM,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,EAAE;gBAChC,UAAU,GAAG,OAAO,CAAC;YACzB,CAAC,CAAC,CAAC;QACP,CAAC;IACL,CAAC;IAED,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,EAAE,UAAU,EAAE,UAAU,EAAE,EAAE,CAAC;AACpE,CAAC"}
package/package.json ADDED
@@ -0,0 +1,66 @@
1
+ {
2
+ "name": "@salesforce/sfdx-agent-harness-openai",
3
+ "version": "0.0.1",
4
+ "description": "OpenAI Agents SDK-backed AgentHarness implementation for @salesforce/sfdx-agent-sdk",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": "./dist/index.js"
10
+ },
11
+ "scripts": {
12
+ "build": "tsc --build",
13
+ "clean": "tsc --build --clean",
14
+ "clean:all": "npm run clean && rimraf node_modules",
15
+ "postclean": "rimraf coverage && rimraf dist",
16
+ "format": "prettier --write .",
17
+ "lint": "eslint .",
18
+ "lint:fix": "eslint . --fix",
19
+ "showcoverage": "open ./coverage/lcov-report/index.html",
20
+ "test": "tsc --build ./test/tsconfig.json && vitest run --coverage",
21
+ "test:conformance": "tsc --build ./test/tsconfig.json && vitest run test/conformance"
22
+ },
23
+ "license": "SEE LICENSE IN LICENSE.txt",
24
+ "files": [
25
+ "dist",
26
+ "CHANGELOG.md",
27
+ "LICENSE.txt"
28
+ ],
29
+ "dependencies": {
30
+ "@openai/agents": "^0.13.0",
31
+ "@salesforce/agentic-common": "0.13.0",
32
+ "openai": "^6.0.0"
33
+ },
34
+ "peerDependencies": {
35
+ "@salesforce/sfdx-agent-sdk": "0.35.0"
36
+ },
37
+ "devDependencies": {
38
+ "@eslint/js": "^10.0.1",
39
+ "@salesforce/harness-conformance": "0.0.1",
40
+ "@salesforce/sfdx-agent-sdk": "0.35.0",
41
+ "@types/node": "^22.20.0",
42
+ "@vitest/coverage-istanbul": "^4.1.10",
43
+ "@vitest/eslint-plugin": "^1.6.22",
44
+ "eslint": "^10.7.0",
45
+ "eslint-config-prettier": "^10.1.8",
46
+ "eslint-import-resolver-typescript": "^4.4.5",
47
+ "eslint-plugin-import": "^2.32.0",
48
+ "eslint-plugin-n": "^18.2.1",
49
+ "globals": "^17.6.0",
50
+ "lint-staged": "^17.0.7",
51
+ "prettier": "^3.9.4",
52
+ "rimraf": "^6.1.3",
53
+ "tsx": "^4.23.0",
54
+ "typescript": "^6.0.3",
55
+ "typescript-eslint": "^8.63.0",
56
+ "vitest": "^4.1.8"
57
+ },
58
+ "engines": {
59
+ "node": ">=22.22.0"
60
+ },
61
+ "lint-staged": {
62
+ "*.{js,jsx,ts,tsx,json,md}": [
63
+ "prettier --write"
64
+ ]
65
+ }
66
+ }