dsh-github-copilot 0.4.0-alpha.71 → 0.4.0-alpha.73
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/AGENTS.md +4 -1
- package/CHANGELOG.md +12 -0
- package/README.md +9 -8
- package/README.zh.md +9 -8
- package/deployment-baseline.json +20 -1
- package/docs/copilot-usage.md +12 -0
- package/lib/client.js +248 -101
- package/lib/client.js.map +1 -1
- package/lib/index.js +203 -3
- package/lib/types/context-evidence-ui.d.ts +11 -0
- package/lib/types/context-evidence.d.ts +108 -0
- package/lib/types/context-usage-guard.d.ts +10 -0
- package/package.json +2 -1
package/lib/index.js
CHANGED
|
@@ -1646,9 +1646,208 @@ let GitHubCopilotUsageController = (() => {
|
|
|
1646
1646
|
};
|
|
1647
1647
|
})();
|
|
1648
1648
|
//#endregion
|
|
1649
|
+
//#region lib/types/context-usage-guard.js
|
|
1650
|
+
/** All observed counters are zero, not proof that an attempted prompt was empty. */
|
|
1651
|
+
function isZeroContextUsage(usage) {
|
|
1652
|
+
return usage.inputTokens === 0 && usage.outputTokens === 0 && (usage.cacheReadTokens ?? 0) === 0 && (usage.cacheWriteTokens ?? 0) === 0 && (usage.totalTokens ?? 0) === 0 && (usage.reasoningTokens ?? 0) === 0;
|
|
1653
|
+
}
|
|
1654
|
+
/**
|
|
1655
|
+
* Native pi-ai emits terminal usage immediately before finish, including a
|
|
1656
|
+
* default zero sample when no provider usage arrived. Delay only that sample;
|
|
1657
|
+
* failed, cancelled or truncated attempts must not reset Core's last reading.
|
|
1658
|
+
*/
|
|
1659
|
+
async function* guardContextUsage(stream) {
|
|
1660
|
+
let pending;
|
|
1661
|
+
for await (const chunk of stream) {
|
|
1662
|
+
if (pending !== void 0) {
|
|
1663
|
+
if (chunk.type !== "finish" || chunk.reason.kind !== "error" && chunk.reason.kind !== "aborted") yield pending;
|
|
1664
|
+
pending = void 0;
|
|
1665
|
+
}
|
|
1666
|
+
if (chunk.type === "usage" && isZeroContextUsage(chunk.usage)) pending = chunk;
|
|
1667
|
+
else yield chunk;
|
|
1668
|
+
}
|
|
1669
|
+
}
|
|
1670
|
+
//#endregion
|
|
1671
|
+
//#region lib/types/context-evidence.js
|
|
1672
|
+
const COPILOT_CONTEXT_EVIDENCE = "githubCopilotContextEvidence";
|
|
1673
|
+
const count = z$1.number().int().min(0).max(Number.MAX_SAFE_INTEGER);
|
|
1674
|
+
const routeSchema = z$1.object({
|
|
1675
|
+
provider: z$1.string().min(1),
|
|
1676
|
+
model: z$1.string().min(1)
|
|
1677
|
+
}).strict();
|
|
1678
|
+
const sampleSchema = z$1.object({
|
|
1679
|
+
tokens: count,
|
|
1680
|
+
seq: count,
|
|
1681
|
+
route: routeSchema
|
|
1682
|
+
}).strict();
|
|
1683
|
+
const ContextEvidenceSchema = z$1.object({
|
|
1684
|
+
route: routeSchema.nullable(),
|
|
1685
|
+
sample: sampleSchema.nullable(),
|
|
1686
|
+
invalid: z$1.boolean(),
|
|
1687
|
+
reason: z$1.enum([
|
|
1688
|
+
"none",
|
|
1689
|
+
"failed-zero",
|
|
1690
|
+
"compaction",
|
|
1691
|
+
"selection",
|
|
1692
|
+
"unknown"
|
|
1693
|
+
])
|
|
1694
|
+
}).strict();
|
|
1695
|
+
const usageSchema = z$1.object({
|
|
1696
|
+
inputTokens: count,
|
|
1697
|
+
outputTokens: count,
|
|
1698
|
+
cacheReadTokens: count.optional(),
|
|
1699
|
+
cacheWriteTokens: count.optional(),
|
|
1700
|
+
totalTokens: count.optional(),
|
|
1701
|
+
reasoningTokens: count.optional()
|
|
1702
|
+
});
|
|
1703
|
+
function record$4(value) {
|
|
1704
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1705
|
+
}
|
|
1706
|
+
function sameRoute$1(left, right) {
|
|
1707
|
+
return left !== null && right !== null && left.provider === right.provider && left.model === right.model;
|
|
1708
|
+
}
|
|
1709
|
+
function copilot(route) {
|
|
1710
|
+
return route?.provider === "github-copilot" || route?.provider === "github-copilot-preview";
|
|
1711
|
+
}
|
|
1712
|
+
function initialContextEvidence() {
|
|
1713
|
+
return {
|
|
1714
|
+
route: null,
|
|
1715
|
+
sample: null,
|
|
1716
|
+
invalid: false,
|
|
1717
|
+
reason: "none"
|
|
1718
|
+
};
|
|
1719
|
+
}
|
|
1720
|
+
/** Read only counts and routing leaves; never message content or opaque replay. */
|
|
1721
|
+
function foldContextEvidence(state, event) {
|
|
1722
|
+
if (!record$4(event) || typeof event.type !== "string" || !record$4(event.data)) return state;
|
|
1723
|
+
if (event.type === "request/header" || event.type === "model/selection") {
|
|
1724
|
+
const raw = event.type === "request/header" ? record$4(event.data.header) ? event.data.header.config : void 0 : event.data;
|
|
1725
|
+
if (!record$4(raw)) return {
|
|
1726
|
+
...state,
|
|
1727
|
+
route: null,
|
|
1728
|
+
sample: null,
|
|
1729
|
+
invalid: true,
|
|
1730
|
+
reason: "unknown"
|
|
1731
|
+
};
|
|
1732
|
+
const parsed = routeSchema.safeParse({
|
|
1733
|
+
provider: raw.provider,
|
|
1734
|
+
model: raw.model
|
|
1735
|
+
});
|
|
1736
|
+
if (!parsed.success) return {
|
|
1737
|
+
...state,
|
|
1738
|
+
route: null,
|
|
1739
|
+
sample: null,
|
|
1740
|
+
invalid: true,
|
|
1741
|
+
reason: "unknown"
|
|
1742
|
+
};
|
|
1743
|
+
const route = parsed.data;
|
|
1744
|
+
if (sameRoute$1(state.route, route)) return state;
|
|
1745
|
+
return {
|
|
1746
|
+
...state,
|
|
1747
|
+
route,
|
|
1748
|
+
sample: null,
|
|
1749
|
+
reason: "selection"
|
|
1750
|
+
};
|
|
1751
|
+
}
|
|
1752
|
+
if (event.type.startsWith("compaction/") || event.surfaceOp !== void 0 && event.surfaceOp !== "append") {
|
|
1753
|
+
if (state.sample === null) return state;
|
|
1754
|
+
return {
|
|
1755
|
+
...state,
|
|
1756
|
+
sample: null,
|
|
1757
|
+
reason: "compaction"
|
|
1758
|
+
};
|
|
1759
|
+
}
|
|
1760
|
+
if (event.type !== "assistant/message" && event.type !== "assistant/attempt") return state;
|
|
1761
|
+
if (!copilot(state.route)) return state;
|
|
1762
|
+
if (event.type === "assistant/message" && event.data.source !== void 0) {
|
|
1763
|
+
const source = event.data.source;
|
|
1764
|
+
const parsed = routeSchema.safeParse(record$4(source) ? {
|
|
1765
|
+
provider: source.provider,
|
|
1766
|
+
model: source.model
|
|
1767
|
+
} : source);
|
|
1768
|
+
if (!parsed.success || !sameRoute$1(state.route, parsed.data)) return {
|
|
1769
|
+
...state,
|
|
1770
|
+
sample: null,
|
|
1771
|
+
invalid: true,
|
|
1772
|
+
reason: "unknown"
|
|
1773
|
+
};
|
|
1774
|
+
}
|
|
1775
|
+
const stream = Array.isArray(event.data.stream) ? event.data.stream : [];
|
|
1776
|
+
let usage = event.type === "assistant/message" ? event.data.usage : void 0;
|
|
1777
|
+
const settledUsage = usage !== void 0;
|
|
1778
|
+
let terminal;
|
|
1779
|
+
for (const entry of stream) {
|
|
1780
|
+
if (!record$4(entry) || entry.type !== "chunk" || !record$4(entry.chunk)) continue;
|
|
1781
|
+
if (!settledUsage && entry.chunk.type === "usage") usage = entry.chunk.usage;
|
|
1782
|
+
if (entry.chunk.type === "finish") terminal = entry.chunk.reason;
|
|
1783
|
+
}
|
|
1784
|
+
if (usage === void 0) return state;
|
|
1785
|
+
const parsed = usageSchema.safeParse(usage);
|
|
1786
|
+
if (!parsed.success || !count.safeParse(event.seq).success) return {
|
|
1787
|
+
...state,
|
|
1788
|
+
sample: null,
|
|
1789
|
+
invalid: true,
|
|
1790
|
+
reason: "unknown"
|
|
1791
|
+
};
|
|
1792
|
+
const value = parsed.data;
|
|
1793
|
+
const zero = isZeroContextUsage(value);
|
|
1794
|
+
const successful = record$4(terminal) && (terminal.kind === "stop" || terminal.kind === "max-tokens" || terminal.kind === "tool-calls");
|
|
1795
|
+
if (zero && !successful) {
|
|
1796
|
+
const reason = state.sample !== null || state.reason === "none" ? "failed-zero" : state.reason;
|
|
1797
|
+
return {
|
|
1798
|
+
...state,
|
|
1799
|
+
invalid: true,
|
|
1800
|
+
reason
|
|
1801
|
+
};
|
|
1802
|
+
}
|
|
1803
|
+
const tokens = value.inputTokens + (value.cacheReadTokens ?? 0) + (value.cacheWriteTokens ?? 0);
|
|
1804
|
+
if (!Number.isSafeInteger(tokens) || state.route === null) return {
|
|
1805
|
+
...state,
|
|
1806
|
+
sample: null,
|
|
1807
|
+
invalid: true,
|
|
1808
|
+
reason: "unknown"
|
|
1809
|
+
};
|
|
1810
|
+
return {
|
|
1811
|
+
...state,
|
|
1812
|
+
sample: {
|
|
1813
|
+
tokens,
|
|
1814
|
+
seq: count.parse(event.seq),
|
|
1815
|
+
route: state.route
|
|
1816
|
+
},
|
|
1817
|
+
invalid: false,
|
|
1818
|
+
reason: "none"
|
|
1819
|
+
};
|
|
1820
|
+
}
|
|
1821
|
+
/** Separate bounded replay unit; never register under or modify a Core key. */
|
|
1822
|
+
const contextEvidenceDefinition = {
|
|
1823
|
+
key: COPILOT_CONTEXT_EVIDENCE,
|
|
1824
|
+
stateVersion: 1,
|
|
1825
|
+
stateSchema: ContextEvidenceSchema,
|
|
1826
|
+
init: initialContextEvidence,
|
|
1827
|
+
apply: foldContextEvidence,
|
|
1828
|
+
wire: {
|
|
1829
|
+
viewSchema: ContextEvidenceSchema,
|
|
1830
|
+
view: (state) => state
|
|
1831
|
+
}
|
|
1832
|
+
};
|
|
1833
|
+
function installContextEvidence(ctx) {
|
|
1834
|
+
ctx.inject(["sessionProjections"], (scope) => {
|
|
1835
|
+
const registry = scope.get("sessionProjections");
|
|
1836
|
+
if (!record$4(registry) || typeof registry.register !== "function") {
|
|
1837
|
+
scope.logger.warn("[github-copilot] COPILOT_CONTEXT_PROJECTION_UNAVAILABLE");
|
|
1838
|
+
return;
|
|
1839
|
+
}
|
|
1840
|
+
const remove = registry.register(contextEvidenceDefinition);
|
|
1841
|
+
if (typeof remove !== "function") throw new Error("COPILOT_CONTEXT_PROJECTION_DISPOSER_UNAVAILABLE");
|
|
1842
|
+
return () => {
|
|
1843
|
+
remove();
|
|
1844
|
+
};
|
|
1845
|
+
});
|
|
1846
|
+
}
|
|
1847
|
+
//#endregion
|
|
1649
1848
|
//#region package.json
|
|
1650
1849
|
var name$1 = "dsh-github-copilot";
|
|
1651
|
-
var version = "0.4.0-alpha.
|
|
1850
|
+
var version = "0.4.0-alpha.73";
|
|
1652
1851
|
//#endregion
|
|
1653
1852
|
//#region lib/types/probe.js
|
|
1654
1853
|
/**
|
|
@@ -7491,7 +7690,7 @@ var PreviewAdapter = class extends PiAiAdapter {
|
|
|
7491
7690
|
}
|
|
7492
7691
|
guardedStream(lease, options) {
|
|
7493
7692
|
const owner = this;
|
|
7494
|
-
return (async function* () {
|
|
7693
|
+
return guardContextUsage((async function* () {
|
|
7495
7694
|
owner.lifetime.start(lease);
|
|
7496
7695
|
owned(options.provider);
|
|
7497
7696
|
if (options.model !== lease.descriptor.id) throw failure("COPILOT_PREVIEW_MODEL_MISMATCH");
|
|
@@ -7561,7 +7760,7 @@ var PreviewAdapter = class extends PiAiAdapter {
|
|
|
7561
7760
|
if (cause instanceof LlmError && cause.code === "UNKNOWN_MODEL") await owner.refreshRejected(lease.snapshot, signal);
|
|
7562
7761
|
throw requestFailure ?? cause;
|
|
7563
7762
|
}
|
|
7564
|
-
})();
|
|
7763
|
+
})());
|
|
7565
7764
|
}
|
|
7566
7765
|
excludedModels() {
|
|
7567
7766
|
return excludedModelSet(this.accountModelSettings().excludedModelIds);
|
|
@@ -8009,6 +8208,7 @@ function observeSettingsNamespace(ctx, namespace, config, hooks) {
|
|
|
8009
8208
|
*/
|
|
8010
8209
|
function apply(ctx, config) {
|
|
8011
8210
|
installCopilotToolSchemaCompatibility(ctx);
|
|
8211
|
+
installContextEvidence(ctx);
|
|
8012
8212
|
let promptText = () => "";
|
|
8013
8213
|
ctx.on("system-prompt/assemble", async (_assembly, _context, next) => {
|
|
8014
8214
|
const owner = currentSearchInitiator(ctx);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
2
|
+
import type { ReactElement } from 'react';
|
|
3
|
+
import type { ContextEvidence } from './context-evidence.ts';
|
|
4
|
+
export declare function ContextEvidenceNotice({ evidence, locale, applicable }: {
|
|
5
|
+
evidence: ContextEvidence | undefined;
|
|
6
|
+
locale?: string;
|
|
7
|
+
applicable?: boolean;
|
|
8
|
+
}): ReactElement | null;
|
|
9
|
+
/** Additive disclosure only: native input, context ring and billing remain untouched. */
|
|
10
|
+
export declare function registerContextEvidenceUi(ctx: Context): () => void;
|
|
11
|
+
//# sourceMappingURL=context-evidence-ui.d.ts.map
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
3
|
+
export declare const COPILOT_CONTEXT_EVIDENCE = "githubCopilotContextEvidence";
|
|
4
|
+
export declare const ContextEvidenceSchema: z.ZodObject<{
|
|
5
|
+
route: z.ZodNullable<z.ZodObject<{
|
|
6
|
+
provider: z.ZodString;
|
|
7
|
+
model: z.ZodString;
|
|
8
|
+
}, z.core.$strict>>;
|
|
9
|
+
sample: z.ZodNullable<z.ZodObject<{
|
|
10
|
+
tokens: z.ZodNumber;
|
|
11
|
+
seq: z.ZodNumber;
|
|
12
|
+
route: z.ZodObject<{
|
|
13
|
+
provider: z.ZodString;
|
|
14
|
+
model: z.ZodString;
|
|
15
|
+
}, z.core.$strict>;
|
|
16
|
+
}, z.core.$strict>>;
|
|
17
|
+
invalid: z.ZodBoolean;
|
|
18
|
+
reason: z.ZodEnum<{
|
|
19
|
+
none: "none";
|
|
20
|
+
compaction: "compaction";
|
|
21
|
+
unknown: "unknown";
|
|
22
|
+
selection: "selection";
|
|
23
|
+
"failed-zero": "failed-zero";
|
|
24
|
+
}>;
|
|
25
|
+
}, z.core.$strict>;
|
|
26
|
+
export type ContextEvidence = z.infer<typeof ContextEvidenceSchema>;
|
|
27
|
+
declare module '@deepseek-ai/dsh-session-projection/types' {
|
|
28
|
+
interface SessionProjectionMap {
|
|
29
|
+
githubCopilotContextEvidence: ContextEvidence;
|
|
30
|
+
}
|
|
31
|
+
interface SessionProjectionStateMap {
|
|
32
|
+
githubCopilotContextEvidence: ContextEvidence;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
export declare function initialContextEvidence(): ContextEvidence;
|
|
36
|
+
/** Read only counts and routing leaves; never message content or opaque replay. */
|
|
37
|
+
export declare function foldContextEvidence(state: ContextEvidence, event: unknown): ContextEvidence;
|
|
38
|
+
/** Separate bounded replay unit; never register under or modify a Core key. */
|
|
39
|
+
export declare const contextEvidenceDefinition: {
|
|
40
|
+
key: "githubCopilotContextEvidence";
|
|
41
|
+
stateVersion: number;
|
|
42
|
+
stateSchema: z.ZodObject<{
|
|
43
|
+
route: z.ZodNullable<z.ZodObject<{
|
|
44
|
+
provider: z.ZodString;
|
|
45
|
+
model: z.ZodString;
|
|
46
|
+
}, z.core.$strict>>;
|
|
47
|
+
sample: z.ZodNullable<z.ZodObject<{
|
|
48
|
+
tokens: z.ZodNumber;
|
|
49
|
+
seq: z.ZodNumber;
|
|
50
|
+
route: z.ZodObject<{
|
|
51
|
+
provider: z.ZodString;
|
|
52
|
+
model: z.ZodString;
|
|
53
|
+
}, z.core.$strict>;
|
|
54
|
+
}, z.core.$strict>>;
|
|
55
|
+
invalid: z.ZodBoolean;
|
|
56
|
+
reason: z.ZodEnum<{
|
|
57
|
+
none: "none";
|
|
58
|
+
compaction: "compaction";
|
|
59
|
+
unknown: "unknown";
|
|
60
|
+
selection: "selection";
|
|
61
|
+
"failed-zero": "failed-zero";
|
|
62
|
+
}>;
|
|
63
|
+
}, z.core.$strict>;
|
|
64
|
+
init: typeof initialContextEvidence;
|
|
65
|
+
apply: typeof foldContextEvidence;
|
|
66
|
+
wire: {
|
|
67
|
+
viewSchema: z.ZodObject<{
|
|
68
|
+
route: z.ZodNullable<z.ZodObject<{
|
|
69
|
+
provider: z.ZodString;
|
|
70
|
+
model: z.ZodString;
|
|
71
|
+
}, z.core.$strict>>;
|
|
72
|
+
sample: z.ZodNullable<z.ZodObject<{
|
|
73
|
+
tokens: z.ZodNumber;
|
|
74
|
+
seq: z.ZodNumber;
|
|
75
|
+
route: z.ZodObject<{
|
|
76
|
+
provider: z.ZodString;
|
|
77
|
+
model: z.ZodString;
|
|
78
|
+
}, z.core.$strict>;
|
|
79
|
+
}, z.core.$strict>>;
|
|
80
|
+
invalid: z.ZodBoolean;
|
|
81
|
+
reason: z.ZodEnum<{
|
|
82
|
+
none: "none";
|
|
83
|
+
compaction: "compaction";
|
|
84
|
+
unknown: "unknown";
|
|
85
|
+
selection: "selection";
|
|
86
|
+
"failed-zero": "failed-zero";
|
|
87
|
+
}>;
|
|
88
|
+
}, z.core.$strict>;
|
|
89
|
+
view: (state: ContextEvidence) => {
|
|
90
|
+
route: {
|
|
91
|
+
provider: string;
|
|
92
|
+
model: string;
|
|
93
|
+
} | null;
|
|
94
|
+
sample: {
|
|
95
|
+
tokens: number;
|
|
96
|
+
seq: number;
|
|
97
|
+
route: {
|
|
98
|
+
provider: string;
|
|
99
|
+
model: string;
|
|
100
|
+
};
|
|
101
|
+
} | null;
|
|
102
|
+
invalid: boolean;
|
|
103
|
+
reason: "none" | "compaction" | "unknown" | "selection" | "failed-zero";
|
|
104
|
+
};
|
|
105
|
+
};
|
|
106
|
+
};
|
|
107
|
+
export declare function installContextEvidence(ctx: Context): void;
|
|
108
|
+
//# sourceMappingURL=context-evidence.d.ts.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { StreamChunk, TokenUsage } from '@deepseek-ai/dsh-llm';
|
|
2
|
+
/** All observed counters are zero, not proof that an attempted prompt was empty. */
|
|
3
|
+
export declare function isZeroContextUsage(usage: TokenUsage): boolean;
|
|
4
|
+
/**
|
|
5
|
+
* Native pi-ai emits terminal usage immediately before finish, including a
|
|
6
|
+
* default zero sample when no provider usage arrived. Delay only that sample;
|
|
7
|
+
* failed, cancelled or truncated attempts must not reset Core's last reading.
|
|
8
|
+
*/
|
|
9
|
+
export declare function guardContextUsage(stream: AsyncIterable<StreamChunk>): AsyncGenerator<StreamChunk>;
|
|
10
|
+
//# sourceMappingURL=context-usage-guard.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-github-copilot",
|
|
3
3
|
"description": "DSH companion for GitHub Copilot sign-in, account-aware model profiles, tool compatibility, and provider-hosted search.",
|
|
4
|
-
"version": "0.4.0-alpha.
|
|
4
|
+
"version": "0.4.0-alpha.73",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public",
|
|
7
7
|
"registry": "https://registry.npmjs.org/",
|
|
@@ -167,6 +167,7 @@
|
|
|
167
167
|
"@deepseek-ai/dsh-scope": "0.2.0-rc.2",
|
|
168
168
|
"@deepseek-ai/dsh-session": "0.2.0-rc.2",
|
|
169
169
|
"@deepseek-ai/dsh-session-format-catalog": "0.2.0-rc.2",
|
|
170
|
+
"@deepseek-ai/dsh-session-projection": "0.2.0-rc.2",
|
|
170
171
|
"@deepseek-ai/dsh-settings": "0.2.0-rc.2",
|
|
171
172
|
"@deepseek-ai/dsh-system-prompt": "0.2.0-rc.2",
|
|
172
173
|
"@deepseek-ai/dsh-tool-web": "0.2.0-rc.2",
|